hi
I need to have a vba macro to autofilter, then copy the results, without the header, to a different sheet. I have a number of them working in other worksheets, but this new sheet seems to throw up some issues for some reason.
Here is what I have
I found it generated a RE 1004 error, "Method of range class failed"on the line
You can see that there are various columns hidden from L onwards. When copying and pasting, only any visible cells up to L are copied. Anything visible after L is not copied.
The other issue is when there is nothing to copy. An RE message comes up on the destination workbook line. That workbook is not stored locally, but rather in a dropbox folder, yet I have the workbook open when running the macro.
Any thoughts on firstly why all visible cells are NOT being copied and, secondly, how to stop the error message when there is nothing to copy and paste?
Thanks in advance
I need to have a vba macro to autofilter, then copy the results, without the header, to a different sheet. I have a number of them working in other worksheets, but this new sheet seems to throw up some issues for some reason.
Here is what I have
VBA Code:
Sub OO_Away_Lay_1()
'
' OO Away Lay v1 Macro
' This macro will filter for 1x2
'
Dim ws As Worksheet, lc As Long, lr As Long
Set ws = ActiveSheet
'range from A1 to last column header and last row
lc = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
lr = ws.Cells.Find("*", after:=ws.Range("A1"), LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
With ws.Range("A1", ws.Cells(lr, lc))
.HorizontalAlignment = xlCenter
Selection.AutoFilter
.AutoFilter Field:=24, Criteria1:="Draw", Operator:=xlFilterValues
If .Rows.Count - 1 > 0 Then
On Error Resume Next
.Columns("L:S").EntireColumn.Hidden = True
.Columns("U:W").EntireColumn.Hidden = True
.Columns("Y:CK").EntireColumn.Hidden = True
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy
On Error GoTo 0
Else
Exit Sub
End If
End With
Workbooks("Predictology_Trading Template v3.1.xlsm").Sheets("OO Away Lay v1") _
.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub
I found it generated a RE 1004 error, "Method of range class failed"on the line
Selection.AutoFilter
. When I removed that line, the error message disappeared, but there are still some other issues.You can see that there are various columns hidden from L onwards. When copying and pasting, only any visible cells up to L are copied. Anything visible after L is not copied.
The other issue is when there is nothing to copy. An RE message comes up on the destination workbook line. That workbook is not stored locally, but rather in a dropbox folder, yet I have the workbook open when running the macro.
Any thoughts on firstly why all visible cells are NOT being copied and, secondly, how to stop the error message when there is nothing to copy and paste?
Thanks in advance