SOLVED

Use a macro to autofill a column until the end of the data in another row

%3CLINGO-SUB%20id%3D%22lingo-sub-1709374%22%20slang%3D%22en-US%22%3EUse%20a%20macro%20to%20autofill%20a%20column%20until%20the%20end%20of%20the%20data%20in%20another%20row%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1709374%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22lia-message-subject-wrapper%20lia-component-subject%20lia-component-message-view-widget-subject-with-options%22%3E%3CSPAN%3EHello%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-body%20lia-component-message-view-widget-body%20lia-component-body-signature-highlight-escalation%20lia-component-message-view-widget-body-signature-highlight-escalation%22%3E%3CDIV%20class%3D%22lia-message-body-content%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20consolidating%20category%20data%20ahead%20of%20the%20holidays%20and%20it's%20taking%20a%20lot%20of%20time%20to%20do%20it%20manually.%20Basically%2C%26nbsp%3BI%20need%20some%20help%20with%20the%20following%20problem%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20Macro%20should%20select%20the%20first%20cell%20with%20data%20(A1%20in%20the%20attached%20spreadsheet)%20and%20autofill%20it%20into%20column%20E.%20until%20the%20last%20row%20before%20the%20space%20(E40%20in%20this%20case).%20Then%20it%20will%20select%20the%20second%20category%20(A42%20in%20the%20attached)%20and%20autofill%20into%20column%20E%20for%20rows%20E46-E59%20and%20so%20on%20and%20so%20forth.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20problem%20with%20this%20is%2C%20that%20the%20number%20of%20rows%20with%20data%20always%20change%20every%20week.%20So%20I%20cannot%20use%20a%20static%20row%20number%20although%20the%20number%20of%20categories%20will%20likely%20stay%20the%20same.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAny%20help%20would%20be%20great.%20Thank%20you%20so%20much!%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EBest%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ERyan%3C%2FSPAN%3E%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1709374%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1714839%22%20slang%3D%22en-US%22%3ERe%3A%20Use%20a%20macro%20to%20autofill%20a%20column%20until%20the%20end%20of%20the%20data%20in%20another%20row%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1714839%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F806597%22%20target%3D%22_blank%22%3E%40RyanRR1983%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20understand%20correctly%2C%20you%20want%20to%20duplicate%20values%20from%20column%20A%20to%20column%20E%2C%20right%3F%26nbsp%3B%20If%20so%2C%20you%20can%20use%20the%20following%20formula%20from%20cell%20E7%20down%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DIF(ISNUMBER(%24A7)%2C%24A7%2C%22%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20wanted%20a%20calculation%20rather%20than%20duplication%2C%20the%20following%20would%20be%20an%20example%20of%20that%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DIF(ISNUMBER(%24A7)%2C%24A7*%24C7%2C%22%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1715438%22%20slang%3D%22en-US%22%3ERe%3A%20Use%20a%20macro%20to%20autofill%20a%20column%20until%20the%20end%20of%20the%20data%20in%20another%20row%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1715438%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F531239%22%20target%3D%22_blank%22%3E%40Charla74%3C%2FA%3E%26nbsp%3BThank%20you%20for%20the%20reply.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20trying%20to%20create%20a%20macro%20that%20will%20automate%20adding%20the%20category%20data%20in%20cell%20A1%2C%20A42%2C%20A60%20and%20so%20on%20to%20each%20of%20the%20products%20listed.%20I've%20included%20an%20example%20of%20what%20the%20spreadsheet%20should%20look%20like%20complete.%20Any%20thoughts%20on%20how%20to%20approach%20this%20problem%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you!%3C%2FP%3E%3CP%3E~Ryan%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1715612%22%20slang%3D%22en-US%22%3ERe%3A%20Use%20a%20macro%20to%20autofill%20a%20column%20until%20the%20end%20of%20the%20data%20in%20another%20row%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1715612%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F806597%22%20target%3D%22_blank%22%3E%40RyanRR1983%3C%2FA%3E%26nbsp%3BI%20suspect%20that%20your%20next%20step%20in%20this%20process%20is%20to%20perform%20some%20sort%20of%20analysis%20on%20Cost%2C%20Qty%20and%20Price%20per%20Product%20Number%20across%20different%20Categories.%20If%20so%2C%20there%20is%20no%20need%20to%20keep%20the%20category%20headers%20and%20empty%20rows%20between%20the%20groups%20of%20product%20numbers.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20my%20suspicion%20is%20correct%2C%20a%20relatively%20simple%20Get%26amp%3BTransform%20Data%20(a.k.a.%3CSPAN%3EPowerQuery%20or%20PQ)%20operation%20will%20fill%20down%20the%20Category%20to%20each%20relevant%20product%20record%20and%20create%20one%20long%20list%20that%20can%20be%20analysed%2C%20grouped%2C%20sorted%2C%20filtered%20however%20you%20want%20it%2C%20e.g.%20in%20a%20Pivot%20Table.%20Sheet2%20in%20the%20attached%20workbook%20contains%20the%20end%20result%20of%20the%20PQ.%20I%20dare%20to%20say%20that%20PQ%20is%20easier%20to%20learn%20and%20maintain%20than%20VBA%2C%20in%20case%20you%20are%20new%20to%20both.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor
Hello,

 

I'm consolidating category data ahead of the holidays and it's taking a lot of time to do it manually. Basically, I need some help with the following problem:

 

The Macro should select the first cell with data (A1 in the attached spreadsheet) and autofill it into column E. until the last row before the space (E40 in this case). Then it will select the second category (A42 in the attached) and autofill into column E for rows E46-E59 and so on and so forth.

 

The problem with this is, that the number of rows with data always change every week. So I cannot use a static row number although the number of categories will likely stay the same. 

 

Any help would be great. Thank you so much! 

 

Best,

Ryan

7 Replies
Highlighted

Hi @RyanRR1983 

 

If I understand correctly, you want to duplicate values from column A to column E, right?  If so, you can use the following formula from cell E7 down:

 

=IF(ISNUMBER($A7),$A7,"")

 

If you wanted a calculation rather than duplication, the following would be an example of that:

 

=IF(ISNUMBER($A7),$A7*$C7,"")

 

Hope this helps.

Highlighted

@Charla74 Thank you for the reply. 

 

I'm trying to create a macro that will automate adding the category data in cell A1, A42, A60 and so on to each of the products listed. I've included an example of what the spreadsheet should look like complete. Any thoughts on how to approach this problem?

 

Thank you!

~Ryan

Highlighted

@RyanRR1983 I suspect that your next step in this process is to perform some sort of analysis on Cost, Qty and Price per Product Number across different Categories. If so, there is no need to keep the category headers and empty rows between the groups of product numbers.

 

If my suspicion is correct, a relatively simple Get&Transform Data (a.k.a.PowerQuery or PQ) operation will fill down the Category to each relevant product record and create one long list that can be analysed, grouped, sorted, filtered however you want it, e.g. in a Pivot Table. Sheet2 in the attached workbook contains the end result of the PQ. I dare to say that PQ is easier to learn and maintain than VBA, in case you are new to both.

Highlighted

@Riny_van_EekelenThank you for the help! You are correct - I'm getting the data and cleaning it up so it's ready for analysis. 

 

To be honest, I'm not familiar with the Get&Transform Data (a.k.a.PowerQuery or PQ) operation. How did you use it to create Sheet 2 in the attached? Any help you can provide would be great. Thank you so much!

 

Best,

Ryan

Highlighted
Best Response confirmed by RyanRR1983 (Occasional Contributor)
Solution

@RyanRR1983 The attached link takes you to, what I considered, a great help in learning PQ. As suggested in this blog, PQ has a bit of a learning curve, but once you get over that it will add a tremendous "toolbox" to Excel.

 

If you follow the first steps, (especially "Importing data from tables") you'll learn how to navigate to the query in the file I uploaded and look at the applied steps. In summary, the query loads the original data, creates a column with the category headers only and gets rid of empty rows. Then, it loads the transformed table back to Excel (that's what you find in Sheet2).

 

 

Highlighted

@Riny_van_Eekelen Thank you again! For some reason I can't find the link you mentioned. Would you mind resending it? 

Highlighted

@RyanRR1983 Sorry about that. Something must have gone wrong earlier.

 

https://exceloffthegrid.com/power-query-introduction/