Dim testingData As Worksheet
Set testingData = ThisWorkbook.Sheets("testingData")
Sub TransferData()
Dim ar As Variant
Dim i As Integer
Dim lr As Long
'I added this VVVVVVVVVVVVV
Dim testingData As Worksheet
Set testingData = ThisWorkbook.Sheets("testingData")
'make certain there is a sheet called "testingData"
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ar = Array("1 ADJUVANT", "2 2,4-D MANY CAS #", "16 ALDICARB", "60 CHLOROTHALONIL", "97 ENDOTHALL", "146 GLYPHOSATE")
'make certain your tabs are named exaclty as the array above!
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For i = 0 To UBound(ar)
testingData.Range("e2", ThisWorkbook.Worksheets("testingData").Range("e" & ThisWorkbook.Worksheets("testingData").Rows.Count).End(xlUp)).AutoFilter 1, ar(i), 7, , 0
lr = testingData.Range("e" & Rows.Count).End(xlUp).Row
If lr > 1 Then
testingData.Range("e2", testingData.Range("e" & testingData.Rows.Count).End(xlUp)).EntireRow.Copy Sheets(ar(i)).Range("A" & Rows.Count).End(3)(2)
Sheets(ar(i)).Columns.AutoFit
End If
Next i
testingData.[e2].AutoFilter
End Sub
Sub TransferData()
Dim ar As Variant, i As Integer, sh As Worksheet
Dim ws As Worksheet: Set ws = Sheets("Testing Data") '---->Sets a value to the variable ws.
ar = Array("1 ADJUVANT", "2 2,4-D MANY CAS #", "16 ALDICARB", _
"60 CHLOROTHALONIL", "97 ENDOTHALL", "146 GLYPHOSATE")
Application.ScreenUpdating = False
For i = 0 To UBound(ar) '---->Looping from the bottom of the array to the top.
Set sh = Sheets(ar(i)) '---->Sets a value to the variable sh.
sh.UsedRange.Offset(1).Clear '---->Clears the destination sheets of data (except headings)ready for new data.
With ws.[A1].CurrentRegion
.AutoFilter 5, ar(i) 'Filters the data set on Column E to find the array values.
.Offset(1).EntireRow.Copy sh.Range("A" & Rows.Count).End(3)(2) '---->Copy/paste to the destination sheets.
.AutoFilter '---->Turns the autofilter off.
sh.Columns.AutoFit '---->Autofits the column widths in the destination sheets.
End With '---->Closes off the With statement.
Next i '---->Moves onto the next array item.
Application.ScreenUpdating = True
End Sub
problem is in this row. To be fair, I don't know what the 7,, 0 means
- Posts
- 7
- Registration date
- Thursday July 25, 2019
- Status
- Member
- Last seen
- July 26, 2019
-Sub TransferData()
Dim ar As Variant
Dim i As Integer
Dim lr As Long
ar = Array("1 ADJUVANT", "2 2,4-D MANY CAS #", "16 ALDICARB", "60 CHLOROTHALONIL", "97 ENDOTHALL", "146 GLYPHOSATE")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For i = 0 To UBound(ar)
testingData.Range("e2" & ":" & testingData.Range("e" & testingData.Rows.Count).End(xlUp)).AutoFilter 1, ar(i), 7, , 0
lr = testingData.Range("e" & Rows.Count).End(xlUp).Row
If lr > 1 Then
testingData.Range("e2", testingData.Range("e" & testingData.Rows.Count).End(xlUp)).EntireRow.Copy Sheets(ar(i)).Range("A" & Rows.Count).End(3)(2)
Sheets(ar(i)).Columns.AutoFit
End If
Next i
testingData.[e2].AutoFilter
- Posts
- 7
- Registration date
- Thursday July 25, 2019
- Status
- Member
- Last seen
- July 26, 2019
-The link is https://ccm.net/forum/affich-972900-copy-rows-to-other-sheets-based-on-value-in-column