Hello,
I'm trying to run this code to filter data from one sheet to another. It does nothing when I run the code. I'm wondering if it has something to do with missing code to activate the workbook or worksheet. Please let me know if you see an error or a better way to do this.
Thanks for any help!
I'm trying to run this code to filter data from one sheet to another. It does nothing when I run the code. I'm wondering if it has something to do with missing code to activate the workbook or worksheet. Please let me know if you see an error or a better way to do this.
Code:
Private Sub FilterCommandButton_Click()
'Copy all cells in columns A thru G
Worksheets("Search Results").Range("B3", Range("B" & Rows.Count).End(xlUp)).Copy _
Worksheets("Filtered Data").Range("A1")
Worksheets("Search Results").Range("AD3", Range("AD" & Rows.Count).End(xlUp)).Copy _
Worksheets("Filtered Data").Range("B1")
Worksheets("Search Results").Range("AE3", Range("AE" & Rows.Count).End(xlUp)).Copy _
Worksheets("Filtered Data").Range("C1")
Worksheets("Search Results").Range("W3", Range("W" & Rows.Count).End(xlUp)).Copy _
Worksheets("Filtered Data").Range("D1")
Worksheets("Search Results").Range("X3", Range("X" & Rows.Count).End(xlUp)).Copy _
Worksheets("Filtered Data").Range("E1")
Worksheets("Search Results").Range("Y3", Range("Y" & Rows.Count).End(xlUp)).Copy _
Worksheets("Filtered Data").Range("F1")
Worksheets("Search Results").Range("Z3", Range("Z" & Rows.Count).End(xlUp)).Copy _
Worksheets("Filtered Data").Range("G1")
'Resize Columns
Worksheets("Filtered Data").Columns("A").ColumnWidth = 12
Worksheets("Filtered Data").Columns("B:C").ColumnWidth = 40
Worksheets("Filtered Data").Columns("D:G").ColumnWidth = 5
'Alignment Center
Worksheets("Filtered Data").Rows("1").HorizontalAlignment = xlCenter
Worksheets("Filtered Data").Columns("A").HorizontalAlignment = xlCenter
Worksheets("Filtered Data").Columns("D:G").HorizontalAlignment = xlCenter
End Sub
Thanks for any help!