Aquila has attended:
Excel VBA Intro Intermediate course
Vba searching a list
hi
I would like my VBA code to search a list for a specified code(number), and if it is not there, should add it onto the bottom of the list. Any suggestions on how I would go about doing this?
RE: vba searching a list
Hi Aquila, thanks for your query. It's a little difficult to write specific code for you, but below is the logic of just one way of possibly achieving what you want:
Dim MyFoundValue As Integer
MyFoundValue = 0
'Select the range of cells containing your list
'Count the number of rows using CurrentRegion.Count
'Set up a loop and move the active cell down the list
For myrow = 1 to Range.CurrentRegion.Rows.Count
If ActiveCell.Value = "myvalue" Then
MyFoundValue = 1
End If
Else
Next row
End If
If MyFoundValue = 0 Then
Offset the row number by 1 (i.e. go to the first empty row under the list)
ActiveCell.Value = "myvalue"
Hope this helps,
Anthony