Resize problem

M

Mathieu

Hi, I am trying to copy cell B1 and them select B2 to B6 by code. So far, I
fail by using this.

Selection.Resize(Range("A1").End(xlDown).Row).paste

How can I code it?

A B C
1 4 Select Copy
2 2
3 4
4 5
5 14
6 9
 
P

Per Jessen

Hi

Try this:

LastRow = Range("A1").End(xlDown).Row
Range("B1").Copy
ActiveSheet.Paste Range("B2:B" & LastRow)

or

LastRow = Range("A1").End(xlDown).Row
Range("B1").Copy Destination:= Range("B2:B" & LastRow)

Regards,
Per
 
M

Mathieu

Hi, thanks, it's working partially to what I need. What if it's not always B1
but instead I want to have the ability to chose the cell I need by using this
Range("A1").End(xlDown) or something like that.

Thanks!
 
M

Mathieu

Hi.

I made a few "trial and error" and I have modified the code a little bit. Do
ou see any problem with this code? and can you briefly explain the "long"
variable, what is i's use? Thanks a lot.

Sub Test2()

Dim lngRows As Long
Dim SRng As Range

lngRows = Range("A1").End(xlDown).Row - 2
Set SRng = Range("A1").End(xlToRight).Offset(2, 0).Resize(lngRows)
SRng.Select 'just for testing

End Sub
 
P

Per Jessen

Hi

I don't see any problems with your code, but I don't know which cells
you expect to be selected.

"Long" is a 4-byte integer ranging in value from -2,147,483,648 to
2,147,483,647
"Integer" is a data type that holds integer variables stored as 2-byte
whole numbers in the range -32,768 to 32,767

Regards,
Per
 
M

Mathieu

Thank you!
--
Mathieu Bouffard


Per Jessen said:
Hi

I don't see any problems with your code, but I don't know which cells
you expect to be selected.

"Long" is a 4-byte integer ranging in value from -2,147,483,648 to
2,147,483,647
"Integer" is a data type that holds integer variables stored as 2-byte
whole numbers in the range -32,768 to 32,767

Regards,
Per
 
Top