highfly921
New Member
Hello everyone,
Please see the file attached! I have this macro 95% done; the only issue I have is that my output data (based on sheet 2 tab list ) is only copying the first row (from the raw data tab) and not the entire dataset - I just need the macro to copy all data and paste in the "output tab" and save it as a new file based on all sheet 2 lists and just from not filtered selection; for example I want to save 3 separate files from this macro based on the codes I have listed from sheet 2 tab list.
I'm almost there but can't figure out the rows section, also I will have 100k +rows & 300+ columns so trying to have an automated process! please help family!
Thanks!
Code:
>>> use code - tags <<<
Please see the file attached! I have this macro 95% done; the only issue I have is that my output data (based on sheet 2 tab list ) is only copying the first row (from the raw data tab) and not the entire dataset - I just need the macro to copy all data and paste in the "output tab" and save it as a new file based on all sheet 2 lists and just from not filtered selection; for example I want to save 3 separate files from this macro based on the codes I have listed from sheet 2 tab list.
I'm almost there but can't figure out the rows section, also I will have 100k +rows & 300+ columns so trying to have an automated process! please help family!
Thanks!
Code:
>>> use code - tags <<<
Code:
Sub filter_copy_paste_save()
Dim region As String
Dim raw As Worksheet
Dim out As Worksheet
Dim count_col As Integer
Dim count_row As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set raw = ThisWorkbook.Sheets("Raw Data")
Set out = ThisWorkbook.Sheets("Output")
region = raw.Range("h1").Text
'clear pervious data
out.Cells.ClearContents
'determine the size of the range
raw.Activate
count_col = WorksheetFunction.CountA(Range("A2", Range("A2").End(xlToRight)))
count_row = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown))) + 2
'filter data on Raw Data tab
raw.Range("A2").AutoFilter field:=2, Criteria1:=region
'copy/paste to Output tab
raw.Range(Cells(2, 1), Cells(count_row, count_col)).SpecialCells(xlCellTypeVisible).Copy
out.Range("A1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
'show data and remove filter
With raw
.ShowAllData
.AutoFilterMode = False
End With
'formatting Output tab
With out
.Activate
.Cells.Select
.Cells.EntireColumn.AutoFit
.Range("A1").Select
.Copy
End With
'save and close the workbook
ActiveWorkbook.SaveAs Filename:="folder location" & _
"Region Report - " & region & ".xlsx"
ActiveWorkbook.Close
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Attachments
Last edited by a moderator: