Can anyone help me with a replacement method for assigning a variable range please?
In the data the length of Row 1 is variable and the location of TargetStr1 is also variable.
At the moment I am using the Intersect function and UsedRange but don't think it's the best way to do it:
Thanks in advance.
In the data the length of Row 1 is variable and the location of TargetStr1 is also variable.
At the moment I am using the Intersect function and UsedRange but don't think it's the best way to do it:
VBA Code:
Sub Estab_Range ()
Dim ws1 As Worksheet
Dim lcol As Long
Dim foundCell As Range, titRng As Range, ListRng As Range
Dim TargetStr1 As String
Set ws1 = ActiveWorkbook.ActiveSheet
lcol = ws1.Range("A1").End(xlToRight).Column
Set titRng = ws1.Range(("A1"), Cells(lcol))
TargetStr1 = "List"
Set foundCell = titRng.Find(what:=TargetStr1, LookIn:=xlValues, _
lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
MatchCase:=True, SearchFormat:=False)
Set ListRng = Intersect(foundCell.EntireColumn, ws1.UsedRange)
End Sub
Thanks in advance.