ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using Range Object With Two Variables (https://www.excelbanter.com/excel-programming/390829-using-range-object-two-variables.html)

ALATL

Using Range Object With Two Variables
 
I get an error when I try & pass the range object two variables. I have
tested this & it allows the use of one varaible. But I would like to use two
variables to copy & paste cell A8:D8. Is there something wrong with my syntax
or will I need to copy & paste one row at a time?


Dim UserName_Addr As String ' Where UserName_Addr = A8
Dim Resp_Addr As String ' Where Resp_Addr = D8

'Copy columns A,B,C, and D from Sheet 1 to Sheet 2
With Sheets("Sheet1")
.Range(.Range("UserName_Addr: Resp_Addr"),
..Range("A65536").End(xlUp)).Copy
End With
Sheets("Sheet2").[A65536].End(xlUp)(1).PasteSpecial Paste:=xlValues


Thx!
ALATL

Norman Jones

Using Range Object With Two Variables
 
Hi Alatl,

Try replacing:

Range("UserName_Addr: Resp_Addr")


with

Range("UserName_Addr & ":" & Resp_Addr")


---
Regards,
Norman



"ALATL" wrote in message
...
I get an error when I try & pass the range object two variables. I have
tested this & it allows the use of one varaible. But I would like to use
two
variables to copy & paste cell A8:D8. Is there something wrong with my
syntax
or will I need to copy & paste one row at a time?


Dim UserName_Addr As String ' Where UserName_Addr = A8
Dim Resp_Addr As String ' Where Resp_Addr = D8

'Copy columns A,B,C, and D from Sheet 1 to Sheet 2
With Sheets("Sheet1")
.Range(.Range("UserName_Addr: Resp_Addr"),
.Range("A65536").End(xlUp)).Copy
End With
Sheets("Sheet2").[A65536].End(xlUp)(1).PasteSpecial Paste:=xlValues


Thx!
ALATL




Alan Beban

Using Range Object With Two Variables
 
Try

..Range(UserName_Addr & ":" & Resp_Addr)

Alan Beban

ALATL wrote:
I get an error when I try & pass the range object two variables. I have
tested this & it allows the use of one varaible. But I would like to use two
variables to copy & paste cell A8:D8. Is there something wrong with my syntax
or will I need to copy & paste one row at a time?


Dim UserName_Addr As String ' Where UserName_Addr = A8
Dim Resp_Addr As String ' Where Resp_Addr = D8

'Copy columns A,B,C, and D from Sheet 1 to Sheet 2
With Sheets("Sheet1")
.Range(.Range("UserName_Addr: Resp_Addr"),
.Range("A65536").End(xlUp)).Copy
End With
Sheets("Sheet2").[A65536].End(xlUp)(1).PasteSpecial Paste:=xlValues


Thx!
ALATL



All times are GMT +1. The time now is 05:10 PM.

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