I am trying to search a sheet for a certain value, in this case "ALAE". After finding this instance, I then need to go down and replace all the subsequent fields with a reference value found on another worksheet.
For example, the field has "ALAE" as a column heading, then below that there are two "2"s. I need to go to the reference sheet, look up what 2 means, and replace the value with the text version. The location of "ALAE" will always change, as well the number of fields beneath the heading. I need to dynamically do this each time the macro is run.
Currently, the code will replace the first "2" but not the second.
here is the code i have so far
Sub Reference()
Dim macroSheet As Worksheet
Dim LastRow As Long
Dim strSearch As String
Dim aCell As Range, bCell As Range
Dim x As Integer
Set macroSheet = Sheets("Treaty Year Preview")
With macroSheet
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
strSearch = "ALAE"
Set aCell = .Range("A1:R" & LastRow).Find(What:=strSearch, LookIn:=xlValues, _
Lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False)
If Not aCell Is Nothing Then
x = 1
Set bCell = aCell
Do
aCell.Offset(x) = Application.WorksheetFunction.VLookup(aCell.Offset(x), Worksheets("ALAE ULAE").Range("A:B"), 2)
x = x + 1
Loop Until aCell.Offset(x) Is Nothing
End If 'If Not aCell is Nothing Then
End With 'With macroSheet
End Sub