J
JLGWhiz
This walks through the code and displays the filtered items, then jumps back
to line one of the code, retraces the original steps and when it hits the
autofilter again it give me an error that AutoFilter failed. I can't figure
out why it won't go to the next step and copy what it had filtered
originally. Can somebody explain what might be missing or what should be
omitted from this code? Appreciate the help.
Private Sub ListBox1_Click()
Dim ws As Worksheet
Dim rng As Range
Dim rng2 As Range
Dim lr4, lc4, mCnt, cnt As Long
lr = Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
lr4 = Sheets("Sheet2").Cells(Rows.Count, 2).End(xlUp).Row
lc4 = Sheets("Sheet2").UsedRange.Columns.Count + 1
Set ws = Worksheets("Sheet1")
Set rng = ws.Range("B26:AD" & lr)
myVar4 = UserForm1.ListBox1.Value
Sheets("Sheet1").Range("A25") = ListBox1.Value
For i = 0 To UserForm1.ListBox1.ListCount - 1
If UserForm1.ListBox1.Selected(i) Then
'With Application
'.ScreenUpdating = False
'.EnableEvents = False
'End With
ws.AutoFilterMode = False
cRng = Sheets("Sheet1").Range("A25").Value
rng.AutoFilter Field:=1, Criteria1:=cRng, VisibleDropDown:=False
ws.AutoFilter.Range.Copy
Sheets("Sheet2").Range("B" & lr + 1).PasteSpecial Paste:=xlValues
ws.AutoFilterMode = False
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If
Next
to line one of the code, retraces the original steps and when it hits the
autofilter again it give me an error that AutoFilter failed. I can't figure
out why it won't go to the next step and copy what it had filtered
originally. Can somebody explain what might be missing or what should be
omitted from this code? Appreciate the help.
Private Sub ListBox1_Click()
Dim ws As Worksheet
Dim rng As Range
Dim rng2 As Range
Dim lr4, lc4, mCnt, cnt As Long
lr = Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
lr4 = Sheets("Sheet2").Cells(Rows.Count, 2).End(xlUp).Row
lc4 = Sheets("Sheet2").UsedRange.Columns.Count + 1
Set ws = Worksheets("Sheet1")
Set rng = ws.Range("B26:AD" & lr)
myVar4 = UserForm1.ListBox1.Value
Sheets("Sheet1").Range("A25") = ListBox1.Value
For i = 0 To UserForm1.ListBox1.ListCount - 1
If UserForm1.ListBox1.Selected(i) Then
'With Application
'.ScreenUpdating = False
'.EnableEvents = False
'End With
ws.AutoFilterMode = False
cRng = Sheets("Sheet1").Range("A25").Value
rng.AutoFilter Field:=1, Criteria1:=cRng, VisibleDropDown:=False
ws.AutoFilter.Range.Copy
Sheets("Sheet2").Range("B" & lr + 1).PasteSpecial Paste:=xlValues
ws.AutoFilterMode = False
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If
Next