Victor Moss
Board Regular
- Joined
- May 3, 2014
- Messages
- 90
Hi guys,
I'd like to do a data validation across multiple worksheets, so on Sheet1 I have Data Validation listing data on a certain sheet. Because I cannot get the result for Data Validation across multiple sheets, I'm using VBA, the Macro needs to run through all sheets except Sheet1, and check each sheet if the Data Validation value exists in Column I of each sheet, if it does, copy the entire row to Sheet1 from row 3 and so forth until all rows have been copied. My code so far:
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim v As Integer
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" Then
For v = 1 To 1000
If ws.Range("I" & v).Value = Sheets("Sheet1").Range("B1").Value Then
ws.Rows(v & ":" & v).Copy
Sheets("Sheet1").Range("A60000").End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
Next v
End If
Next ws
My problem is that it isn't looping through all sheets and copying all rows. Is there something I am missing? I also get a run-time 13 error, Type Mismatch on this row:
If ws.Range("I" & v).Value = Sheets("Sheet1").Range("B1").Value Then
If anyone can help please?
I'd like to do a data validation across multiple worksheets, so on Sheet1 I have Data Validation listing data on a certain sheet. Because I cannot get the result for Data Validation across multiple sheets, I'm using VBA, the Macro needs to run through all sheets except Sheet1, and check each sheet if the Data Validation value exists in Column I of each sheet, if it does, copy the entire row to Sheet1 from row 3 and so forth until all rows have been copied. My code so far:
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim v As Integer
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" Then
For v = 1 To 1000
If ws.Range("I" & v).Value = Sheets("Sheet1").Range("B1").Value Then
ws.Rows(v & ":" & v).Copy
Sheets("Sheet1").Range("A60000").End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
Next v
End If
Next ws
My problem is that it isn't looping through all sheets and copying all rows. Is there something I am missing? I also get a run-time 13 error, Type Mismatch on this row:
If ws.Range("I" & v).Value = Sheets("Sheet1").Range("B1").Value Then
If anyone can help please?