PDA

View Full Version : Copy,Paste,Transpose in VBA loop -Thank you so much!



mytheresa
04-10-2013, 08:27 AM
Hello! I m new to macro and I need to copy the data from row 26:27, 36:37, 46:47 cells value which are converted into E9:F39, P9:Q39, AA9:AB39, 12 columns in the other workbook. How can I do if I want to import the data directly instead of making a copy of the report inside of my workbook by using VBA? Thanks a lot if someone can help me! Thanks a lot!

werafa
04-10-2013, 02:48 PM
The logic for referring to cells in VBA is:
Workbooks(workbookname).worksheets(worksheetname).range(cell or range reference).

The best way for you to figure this one out is to turn on the macro recorder, manually step through the process, and then look at the code that is generated. put an apostrophe (') in front of a line to stop it from executing if you want to see what it does, and use F8 to step through code execution 1 line at a time.

Excel will include a lot of range.select followed by selection.next_command from the macro recorder as this is your actual workflow - you can safely change this to range.next_command in 99% of cases if you want to make your code simpler and more efficient.

my last suggestion for you - learn how to use objects. eg.
dim myRange as range
set myrange = activesheet.range("A1")
as you can then see most of the object properties in the locals window (e.g. you can see 'myrange.value' and 'myrange.font' are properties that exist, and guess that these are the names you need to look up in google to figure out how to do stuff with them.

lastly,
the vba commands you will need are:
Copy
Paste
and Transpose.
(many vba commands are the same as the 'normal' commands with only the spaces removed)

search for each of these in turn by typing 'excel vba copy' etc into your search engine

Regards
Tim