Well I've added a little extra (using your advice on public Dims) and it's doing what I tell it too...kinda
In the following section:
'Below searches for the first address sheet looking for GROUP CODE. It continues to loop until not found.'
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "ESTATE FILE SUMMARY" And ws.Name <> "EVIDENCE AND COUNCIL BAND" And ws.Name <> "AUDIT RECORD" Then
With ws
celltxt = .Range("D2")
x = InStr(1, celltxt, "GROUP CODE")
y = IIf(x > 0, "Yep", "Nope")
If InStr(1, celltxt, "GROUP CODE") Then
ws.Activate
Call CaptureSheetData(Sourcewb, ws, Housenumber) 'This is the Sub at the bottom which SHOULD be called....but its being a *****'
MsgBox "Yep! " & .Name
End If
End With
MsgBox y
End If
Next ws
It searches through a workbook I defined earlier fine and it does indeed find the headers I required in 3 separate sheets. However when it executes the 'CallCapturesheetdata' sub, it only copies the column for the last sheet found.
The capture sheet data code is below:
Sub CaptureSheetData(Sourcewb As Workbook, ws As Worksheet, Housenumber As Variant)
Dim a(), colnum As Long, v
Dim unhideallsheets
Dim x As String
Dim y As String
x = Sourcewb.Name
y = ws.Name
With ActiveSheet
On Error Resume Next
'Find the column number where the column header is'
colnum = Application.WorksheetFunction.Match("House Number", .Rows(2), 0) 'Changed rows 1 to 2 as address sheets are different'
'Get array value from Range(TopLeftCell, BottomRightCell)'
Housenumber = Range(.Cells(3, colnum), .Cells(.Rows.Count, colnum).End(xlUp)).Value ' Change 2 to 3 as adddress sheets are different'
End With
End Sub
There's additional bits for test purposes so it may look a mess.
I'm trying to capture the data from each of the 3 columns on each of the 3 sheets it found the word 'Housenumber' but as stated before it only captures the column on the last found sheet. I may have to try and put them each into a separate array which wouldn't be an issue....it's just getting to that point!
Thanks for your help!
Bookmarks