Hi,
I'm wondering if there is a way to use column name instead of column number with offset function
Let's say we have the following sheet
In this case I have to use different Offset for each condition
I'm wondering if there is a shortcut to use the Offset one time after the If Else statement as the example below
I know that the second code doesn't work, but I'm not sure if it's possible in another way
Or if you have another way to get what I need using another function, it will be appreciated to learn it
Many thanks in advanced
I'm wondering if there is a way to use column name instead of column number with offset function
Let's say we have the following sheet
A | B | c | |
1 | code | Plate | Type |
2 | D1 | 123 | Dozer |
3 | E1 | 456 | Excavator |
VBA Code:
Dim ws as Worksheet
Set ws = Sheet5
If Me.Search_Code_BT.Object = True Then
Set f = ws.Range("C:C").Find(what:=Me.Search_CMB.value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If f Is Nothing Then Exit Sub
Me.Plate_TXT = f.Offset(0, 1)
Me.Type_CMB = f.Offset(0, 2)
'..... the same for other textboxes
ElseIf Me.Search_Plate_BT.Object = True Then
Set f = ws.Range("D:D").Find(what:=Me.Search_CMB.value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If f Is Nothing Then Exit Sub
Me.Code_TXT = f.Offset(0, -1)
Me.Type_CMB = f.Offset(0, 1)
'..... the same for other textboxes
End if
End If
In this case I have to use different Offset for each condition
I'm wondering if there is a shortcut to use the Offset one time after the If Else statement as the example below
VBA Code:
If Me.Search_Code_BT.Object = True Then
Set f = ws.Range("C:C").Find(what:=Me.Search_CMB.value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If f Is Nothing Then Exit Sub
ElseIf Me.Search_Plate_BT.Object = True Then
Set f = ws.Range("D:D").Find(what:=Me.Search_CMB.value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
End If
Me.Plate_TXT = f.Offset(0, B)
Me.Type_CMB = f.Offset(0, C)
'..... the same for other textboxes
I know that the second code doesn't work, but I'm not sure if it's possible in another way
Or if you have another way to get what I need using another function, it will be appreciated to learn it
Many thanks in advanced