View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default Question about how to use range in VBA

Hi

Not sure why the code gives you an error. Which kind of error do you
get.

Your code can be reduced to this single statement, and then you have
no highlighted cells:

Range(Cells(startrow, 1), Cells(endrow, 12)).Copy Worksheets
("SUMM").Cells(startrow, 1)

Hopes this helps.
....
Per


On 22 Jan., 01:24, Andrew wrote:
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