PDA

View Full Version : VBA Copy and Paste HELP



Dimitriy
07-23-2009, 11:37 AM
Hey Everybody,

I am having a problem with copying and pasting the correct range. Please take a look at the attached file. When I run the code, VBA copies range A10:B29, instead of A10:B27, which is what's specified in the code. Can you please point out the problem.

Thanks,
Dimitriy

j19_2002
07-23-2009, 12:50 PM
Sorry, I posted a possible solution but didn't work the 2nd time I ran it, Try Abdul's solution below. I'll keep seeing what the issue is.

mumin_abdul
07-23-2009, 12:52 PM
Sheets(ActiveSheet.Range("B1").Value).Select
Range("A10:B10").End(xlDown).Resize(, -1).Select
Selection.Copy
Sheets("Main Table").Select
Range("A4").Select
ActiveSheet.Paste

mdmackillop
07-23-2009, 01:07 PM
Avoid Select where possible

Sub TEST()
Sheets(ActiveSheet.Range("B1").Value).Select
If Range("A28").End(xlUp).Row > 9 Then
Range("A10", Range("A28").End(xlUp)).Resize(, 5).Copy _
Sheets("Main Table").Range("A4")
'or
Range("A10", Range("A28").End(xlUp)).Resize(, 5).Copy _
Sheets("Main Table").Cells(Rows.Count, 1).End(xlUp).Offset(1)
End If
End Sub

Dimitriy
07-27-2009, 06:41 AM
Thanks, guys, for your help!

mdmackillop
07-27-2009, 07:06 AM
Remember to mark your threads Solved using the Thread Tools dropdown.