Hi - I have multiple worksheets and in each, contain a unique header across varying columns. I also have a range K2:K31 on a worksheet named "qMatrix" which contain specific headers that will be in one or more of these worksheets. The headers in "qMatrix", if they exist in a column header on one of the other worksheets, will be unique - i.e. There will never be more than one match in a column header to the strings held in K2:K31.
What I'm trying to do is loop through each worksheet, find if one of the strings in K2:K31 are found in the column header and if true, get that column number. I'll then use the column number to loop through cells below to delete rows based on my condition.
Here's what I've got so far;
It does nothing though. Doesn't execute anything nor does it present any errors.
Any help would be appreciated.
What I'm trying to do is loop through each worksheet, find if one of the strings in K2:K31 are found in the column header and if true, get that column number. I'll then use the column number to loop through cells below to delete rows based on my condition.
Here's what I've got so far;
VBA Code:
Dim rng1 As Range
Dim c As Range
Dim lastRow As Long, i As Long
Dim ws As Worksheet
lRange = Sheets("qMatrix").Range("K2:K31").Value
For Each ws In Worksheets
Set rng1 = ActiveSheet.UsedRange.Find(lRange, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
lastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = lastRow To 2 Step -1
If Application.Count(ActiveSheet.Range(rng1.Column & i).Resize(, 3)) < 3 Then Rows(i).Delete
Next i
End If
Next
It does nothing though. Doesn't execute anything nor does it present any errors.
Any help would be appreciated.