98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Vba searching a list
Vba searching a list
Resolved · High Priority · Version 2007
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
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Hiding a worksheet in ExcelWant to circulate an Excel workbook file but keep certain worksheets hidden from your colleagues' view? |