I have this code from Mumps that uses a list of names on one sheet to find the name on another WS and hide the row. I am now trying to modify the code to select a specific range of cells after the row number has been determined from the line:
In my test WB, desWS.Rows(dic(v2(i, 1))) returned row 4 as an example. I now want to select the range in row 4 "a4:i4" so I can run a routine on that range.. I've come close to setting a variable for "desWS.Rows(dic(v2(i, 1)))" but I'm not using the right syntax. Am I on the right path here or do I need to start from scratch?
Thanks for looking!
VBA Code:
desWS.Rows(dic(v2(i, 1))).Hidden = True
In my test WB, desWS.Rows(dic(v2(i, 1))) returned row 4 as an example. I now want to select the range in row 4 "a4:i4" so I can run a routine on that range.. I've come close to setting a variable for "desWS.Rows(dic(v2(i, 1)))" but I'm not using the right syntax. Am I on the right path here or do I need to start from scratch?
Thanks for looking!
VBA Code:
Sub HideRows()
Application.ScreenUpdating = False
Dim srcWS As Worksheet, desWS As Worksheet, v1 As Variant, v2 As Variant, i As Long, dic As Object
Set srcWS = Sheets("Sheet2")
Set desWS = Sheets("Sheet1")
v1 = desWS.Range("A1", desWS.Range("A" & Rows.Count).End(xlUp)).Value
v2 = srcWS.Range("A1", srcWS.Range("A" & Rows.Count).End(xlUp)).Value
Set dic = CreateObject("Scripting.Dictionary")
For i = LBound(v1) To UBound(v1)
If Not dic.exists(v1(i, 1)) Then
dic.Add v1(i, 1), i
End If
Next i
For i = LBound(v2) To UBound(v2)
If dic.exists(v2(i, 1)) Then
desWS.Rows(dic(v2(i, 1))).Hidden = True
End If
Next i
Application.ScreenUpdating = True
End Sub