View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Andrew[_56_] Andrew[_56_] is offline
external usenet poster
 
Posts: 130
Default Question about how to use range in VBA

Hello,
I am trying to cut and paste one range from one sheet to the same
range in a different sheet. I used the following code:


Range(Cells(startrow, 1), Cells(endrow, 12)).Select
Selection.Copy

Worksheets("SUMM").Activate
Range(Cells(startrow, 1), Cells(endrow, 12)).Select --- ERROR HERE
ActiveSheet.Paste

This code gives me an error where indicated: Application defined or
Object defined error

Notice that I use the exact same line of code three lines earlier and
I get no error. If I change my code to read as

Range(Cells(startrow, 1), Cells(endrow, 12)).Select
Selection.Copy

Worksheets("SUMM").Activate
Range("A12").Select --- NO ERROR
ActiveSheet.Paste

I get no error. What am I doing wrong?

Also, one other question. When I write Range(Cells(startrow, 1), Cells
(endrow, 12)).Select
I get a bunch of highlighted cells. How do I unselect them in VBA?

thanks