PDA

View Full Version : Solved: Copy rows based on user selection



rgr
12-11-2005, 08:56 AM
I apologize beforehand because I'm a complete idiot when it comes to VBA, but I'm trying to learn as quickly as possible.

I have a macro which will copy a dynamic range of rows and columns into another program after manipulating the columns and padding the strings. It copys all rows that have text. What I am interested in is allowing the user to selectively choose which rows will be copied with a mouse before hitting the copy macro. It may be 1 row or 20 rows. It just so happens that the table already has a column of sequential numbers in column A1:A100, which I would use as the referencing cells.

Can anyone please help me get an idea on how to do this?

Thank you

mdmackillop
12-11-2005, 09:15 AM
Hi RGR,
Welcome to VBAX
Try the following
Regards
MD

Sub DoCopy()
Dim cel As Range
For Each cel In Selection
cel.EntireRow.Copy
Sheets("Sheet2").Activate
Range(cel.Address).Select
ActiveSheet.Paste
Next
End Sub

rgr
12-11-2005, 11:35 AM
Dear MD:

Thank you very much for your quick reply and code sample. I have been fiddling with it for a few hours and it seems that it will fit the bill perfectly. Thank you ever so much.

You will laugh, but I have been wrestling with this for 3 days, coming up with things that were very complicated, unelegant, and, of course, didn't work. Yours is very elegant in its simplicity.

Could you recommend a good book/resource that explains basic things like using undefined ranges and For/each? Everything I look at just seems so incomplete or overly difficult and complicated in its presentation.

Thanks again
rgr

mdmackillop
12-11-2005, 12:12 PM
Hi,
Have a look at the Resources page in the Site Links dropdown for a start.
Regards
MD