Sub test()
Dim rg As Range
Dim a As Variant
Dim i, ii
a = Array("Date", "Time", "Sr No", "Associate")
For i = 1 To 10000
For ii = 0 To UBound(a)
If Cells(i, 1) = a(ii) Then
If rg Is Nothing Then
Set rg = Cells(i, 1)
Else
Set rg = Union(rg, Cells(i, 1))
End If: End If
Next: Next
rg.Select
End Sub
Sub test()
Dim rg As Range
Dim a As Variant
Dim i, ii
a = Array("Date", "Time", "Sr No", "Associate")
For i = 1 To 100
For ii = 0 To UBound(a)
If Cells(1, i) = a(ii) Then
If rg Is Nothing Then
Set rg = Cells(1, i)
Else
Set rg = Union(rg, Cells(1, i))
End If: End If
Next: Next
rg.Select
End Sub
Getting same error :In this case
VBA Code:Sub test() Dim rg As Range Dim a As Variant Dim i, ii a = Array("Date", "Time", "Sr No", "Associate") For i = 1 To 100 For ii = 0 To UBound(a) If Cells(1, i) = a(ii) Then If rg Is Nothing Then Set rg = Cells(1, i) Else Set rg = Union(rg, Cells(1, i)) End If: End If Next: Next rg.Select End Sub
What is the error you get?
It's working fine for excel 2013
a = Array("Date", "Time", "Sr No", "Associate")
If Trim(Cells(1, i)) = a(ii) Then
I see
You have to edit the array in the code
Case sensitiveVBA Code:a = Array("Date", "Time", "Sr No", "Associate")
And just in case replace with this line of code
VBA Code:If Trim(Cells(1, i)) = a(ii) Then