Home

Need help with an Excel Macro

%3CLINGO-SUB%20id%3D%22lingo-sub-575978%22%20slang%3D%22en-US%22%3ENeed%20help%20with%20an%20Excel%20Macro%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-575978%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20new%20to%20creating%20Macros%20and%20would%20like%20to%20know%20if%20there%20is%20a%20way%20to%20write%20a%20macro%20to%20do%20the%20following.%3C%2FP%3E%3CP%3EI%20would%20type%20information%20into%20two%20columns%20in%20Excel%20as%20follows%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CTABLE%20border%3D%221%22%20cellspacing%3D%221%22%20cellpadding%3D%228%22%3E%3CTBODY%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3EQty%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3ELabel%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3E1%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3EApples%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3E2%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3EBananas%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3E4%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3ECarrots%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20then%20run%20a%20macro%20to%20change%20these%20two%20columns%20to%20create%20a%20column%20like%20this%3A%3C%2FP%3E%3CTABLE%20border%3D%221%22%20cellspacing%3D%221%22%20cellpadding%3D%228%22%3E%3CTBODY%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3EApples%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3EBananas%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3EBananas%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3ECarrots%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3ECarrots%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3ECarrots%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%20align%3D%22left%22%3E%3CFONT%20face%3D%22calibri%22%20size%3D%223%22%3ECarrots%3C%2FFONT%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20this%20possible%20by%20using%20a%20macro%3F%26nbsp%3B%20Thank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-575978%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-576763%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20an%20Excel%20Macro%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-576763%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20best%20way%20is%20to%20use%20Get%20%26amp%3B%20Transform%20(aka%20Power%20Query)%20to%20do%20that%20as%20follows%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F113803iECE0F7FAC8EFBBEB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Power%20Query.png%22%20title%3D%22Power%20Query.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20find%20the%20attached%20file%20to%20see%20the%20solution.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETry%20to%20change%20the%20Qty%20number%2C%20then%20go%20to%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3EFruits%20Table%20%26gt%3B%26gt%3B%20Right-click%20%26gt%3B%26gt%3B%20Refresh%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Eand%20see%20how%20it's%20updated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20that%20helps%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F343356%22%20target%3D%22_blank%22%3E%40FarukAhmed%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
FarukAhmed
Occasional Visitor

Hello,

 

I am new to creating Macros and would like to know if there is a way to write a macro to do the following.

I would type information into two columns in Excel as follows:

 

Qty

Label

1

Apples

2

Bananas

4

Carrots

 

I would then run a macro to change these two columns to create a column like this:

Apples

Bananas

Bananas

Carrots

Carrots

Carrots

Carrots

 

Is this possible by using a macro?  Thank you.

1 Reply

Hi,

 

The best way is to use Get & Transform (aka Power Query) to do that as follows:

Power Query.png

 

Please find the attached file to see the solution.

 

Try to change the Qty number, then go to:

Fruits Table >> Right-click >> Refresh

and see how it's updated.

 

Hope that helps

 

@FarukAhmed