Hello attached is an excel sheet with a macro to copy paste columns having specific heading. will someone help me concise the macro. Right now its a huge page of codes. I am new to vba and learning by recording and then modifying.
Hello attached is an excel sheet with a macro to copy paste columns having specific heading. will someone help me concise the macro. Right now its a huge page of codes. I am new to vba and learning by recording and then modifying.
Hi, krash297,
insetad of switching sheets set object to the sheets. And instead of having multiple codes for each item use an array which holds the values and loop through that array:
Ciao,Please Login or Register to view this content.
Holger
Use Code-Tags for showing your code: [code] Your Code here [/code]
Please mark your question Solved if there has been offered a solution that works fine for you
i am new to vba i dont know how to use arrays could you explain me how this works so that i can relate it.
Hi, krash297,
the array stores the names of the items you want to search. In the code it is filled with the line
Any item should be packed in quotes (it it is a string) and be separated by comma. This type of array is zero based which means that the first item will have the number of 0.Please Login or Register to view this content.
Next we do have a loop which will go from the lower bound of the array (as I just stated this will be 0) to the number of items being stored - 1. Instead of writing numbers we use the command LBound (lower bound) and UBound (upper bound) which will free us to alter the code if the number of the items to search for is changed.
Ciao,
Holger
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks