ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Resize problem (https://www.excelbanter.com/excel-programming/420208-resize-problem.html)

Mathieu

Resize problem
 
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).past e

How can I code it?

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

Per Jessen

Resize problem
 
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

"Mathieu" skrev i meddelelsen
...
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).past e

How can I code it?

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



Mathieu

Resize problem
 
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!
--
Mathieu


"Per Jessen" wrote:

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

"Mathieu" skrev i meddelelsen
...
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).past e

How can I code it?

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




Mathieu

Resize problem
 
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
--
Mathieu


"Mathieu" wrote:

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!
--
Mathieu


"Per Jessen" wrote:

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

"Mathieu" skrev i meddelelsen
...
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).past e

How can I code it?

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




Per Jessen[_2_]

Resize problem
 
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

On 18 Nov., 22:48, Mathieu wrote:
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
--
Mathieu



"Mathieu" wrote:
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!
--
Mathieu


"PerJessen" wrote:


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


"Mathieu" skrev i meddelelsen
...
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).past e


How can I code it?


* * * *A * * * * * * * *B * * * * * * * * * * *C
1 * * *4 * * * * * * *Select Copy
2 * * *2
3 * * *4
4 * * *5
5 * * 14
6 * * *9- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -



Mathieu

Resize problem
 
Thank you!
--
Mathieu Bouffard


"Per Jessen" wrote:

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

On 18 Nov., 22:48, Mathieu wrote:
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
--
Mathieu



"Mathieu" wrote:
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!
--
Mathieu


"PerJessen" wrote:


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


"Mathieu" skrev i meddelelsen
...
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).past e


How can I code it?


A B C
1 4 Select Copy
2 2
3 4
4 5
5 14
6 9- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -





All times are GMT +1. The time now is 12:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com