SOLVED

Marco/VBA filter based on the name of sheets and copy paste filtered data to correspondent sheets

%3CLINGO-SUB%20id%3D%22lingo-sub-2694673%22%20slang%3D%22en-US%22%3EMarco%2FVBA%20filter%20based%20on%20the%20name%20of%20sheets%20and%20copy%20paste%20filtered%20data%20to%20correspondent%20sheets%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2694673%22%20slang%3D%22en-US%22%3EHi.%3CBR%20%2F%3E%3CBR%20%2F%3EHope%20everyone%20is%20doing%20well.%3CBR%20%2F%3EI%20was%20trying%20to%20find%20the%20VBA%20code%20which%20will%20allow%20me%20to%20do%20below%20and%20concerned%20the%20possibility.%3CBR%20%2F%3E%3CBR%20%2F%3E1.%20There%20is%20one%20worksheet%20%E2%80%9Craw%20data%E2%80%9D.%20and%20other%20sheets%20named%20by%20different%20code%20with%20same%20format%20and%20template.%3CBR%20%2F%3E%3CBR%20%2F%3E2.%20Trying%20to%20record%20a%20Macro%20by%20copying%20the%20name%20of%20each%20sheet%20in%20a%20row%20and%20autofilter%20column%20A%20in%20%E2%80%9Craw%20data%E2%80%9D%20sheet.%20Then%20copy%20the%20filtered%20data%20without%20headers%20and%20column%20A%20to%20correspondent%20name%20of%20sheet.%3CBR%20%2F%3E%3CBR%20%2F%3E3.%20If%20there%E2%80%99s%20no%20data%20after%20filtering%20then%20skip%20to%20next%20step%2C%20start%20with%20new%20filter.%3CBR%20%2F%3E%3CBR%20%2F%3EChances%20are%20there%20is%20no%20data%20after%20filter%20column%20A%20in%20%E2%80%9Craw%20data%E2%80%9D%20sheets%2C%20I%20added%20Range(%22B3%3AW%22).Selection.SpecialCells(xlCellTypeVisible).Copy%3CBR%20%2F%3E%2C%20but%20somehow%20came%20to%20error%20and%20also%20struggled%20with%20the%20step%203%2C%20If%20worksheet%20is%20Nothing%20Then...%3CBR%20%2F%3E%3CBR%20%2F%3EWondering%20if%20any%20one%20have%20ideas%20about%20this%2C%20already%20attached%20sample%20file%20too%2C%3CBR%20%2F%3Ethanks%20a%20million.%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2694673%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2718273%22%20slang%3D%22en-US%22%3ERe%3A%20Marco%2FVBA%20filter%20based%20on%20the%20name%20of%20sheets%20and%20copy%20paste%20filtered%20data%20to%20correspondent%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2718273%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1139314%22%20target%3D%22_blank%22%3E%40liang_235%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eused%20Power%20Query%20on%20the%20Main%20Tab%3C%2FP%3E%3CP%3ECreated%20reference%20queries%3C%2FP%3E%3CP%3ERenamed%20and%20filtered%20the%20reference%20queries%20according%20to%20the%20data%20filtered%20on%20them%3C%2FP%3E%3CP%3Ewhen%20you%20update%20the%20main%20tab%20then%20press%20ctrl%2Balt%2BF5%20it%20will%20refresh%20the%20master%20query%20as%20well%20as%20all%20the%20reference%20queries%20according%20to%20what%20they're%20filtered%20to%3C%2FP%3E%3CP%3Eto%20add%20a%20new%20reference%20query%3A%3C%2FP%3E%3CP%3Eclick%20data%20then%20the%20icon%20in%20the%20red%20square%20to%20display%20the%20query%20navigation%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yea_So_0-1630694236151.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F308004i8C4B55FFA0F609D1%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yea_So_0-1630694236151.png%22%20alt%3D%22Yea_So_0-1630694236151.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Edouble%20click%20the%20master%20query%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yea_So_1-1630694300416.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F308005i7F631C744268F40D%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yea_So_1-1630694300416.png%22%20alt%3D%22Yea_So_1-1630694300416.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Ein%20the%20queries%20navigation%20panel%20right%20click%20the%20master%20query%20then%20select%20reference%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yea_So_2-1630694378430.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F308006iB7D2E75A376DED99%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yea_So_2-1630694378430.png%22%20alt%3D%22Yea_So_2-1630694378430.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3ERename%20the%20query%20to%20the%20data%20that%20you%20will%20filter%20for%20that%20reference%20query%2C%20then%20click%20close%20and%20load%20then%20save%20the%20file%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Echeers%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2725638%22%20slang%3D%22en-US%22%3ERe%3A%20Marco%2FVBA%20filter%20based%20on%20the%20name%20of%20sheets%20and%20copy%20paste%20filtered%20data%20to%20correspondent%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2725638%22%20slang%3D%22en-US%22%3EMany%20thanks%20for%20your%20alternative%20plan%2C%20it's%20literally%20more%20simple%20and%20understandable.%3CBR%20%2F%3EBut%20kind%20of%20confused%20about%20last%20step%20and%20didn't%20apprehend%20its%20purpose(%20select%20%22reference%22%20and%20new%20query%20created...).%20I'm%20sorry%20if%20I%20asked%20a%20dumb%20question.%3CBR%20%2F%3E%3CBR%20%2F%3Ethanks%20a%20million!!%3C%2FLINGO-BODY%3E
New Contributor
Hi.

Hope everyone is doing well.
I was trying to find the VBA code which will allow me to do below and concerned the possibility.

1. There is one worksheet “raw data”. and other sheets named by different code with same format and template.

2. Trying to record a Macro by copying the name of each sheet in a row and autofilter column A in “raw data” sheet. Then copy the filtered data without headers and column A to correspondent name of sheet.

3. If there’s no data after filtering then skip to next step, start with new filter.

Chances are there is no data after filter column A in “raw data” sheets, I added Range("B3:W").Selection.SpecialCells(xlCellTypeVisible).Copy
, but somehow came to error and also struggled with the step 3, If worksheet is Nothing Then...

Wondering if any one have ideas about this, already attached sample file too,
thanks a million.
5 Replies
best response confirmed by liang_235 (New Contributor)
Solution

@liang_235 

 

used Power Query on the Main Tab

Created reference queries

Renamed and filtered the reference queries according to the data filtered on them

when you update the main tab then press ctrl+alt+F5 it will refresh the master query as well as all the reference queries according to what they're filtered to

to add a new reference query:

click data then the icon in the red square to display the query navigation 

Yea_So_0-1630694236151.png

double click the master query

Yea_So_1-1630694300416.png

in the queries navigation panel right click the master query then select reference

Yea_So_2-1630694378430.png

Rename the query to the data that you will filter for that reference query, then click close and load then save the file

 

cheers

Many thanks for your alternative plan, it's literally more simple and understandable.
But kind of confused about last step and didn't apprehend its purpose( select "reference" and new query created...). I'm sorry if I asked a dumb question.

thanks a million!!
Sorry, I just found out it's for creating new sheet for filtered data.
pls disregard my last reply, thanks a lot.

@liang_235 

 

it is not a dumb question, you are just communicating the area of your confusion to make a clarification and that is a best practice.

 

The reference queries that are named KEL30 for example is the query that will be loaded into the worksheet, as is with all the other reference queries that's why the sheet names are the same names of the reference queries.

 

Try it.  Put new information on existing designations as well as information on new designation, then press ctrl+alt+F5, then look at the designation worksheets that you added new information, then create a new reference query for the new designation that you added for fun and for practice.

When you update the Master Sheet with new information, those existing reference queries will dynamically (automatically) update including the filtering.

 

If the master sheet gets updated with a new designation, for example TZZ01, you will only need to create a reference query for that particular designation and load it into worksheet in the workbook and once you save the workbook the next time you update it it will automatically update the new information to the existing reference queries and all you have to do is create a reference query to new designations that are in the master worksheet.

 

cheers

don't forget to mark your post as answered so it will help other users searching for a similar solution.

cheers