ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Range ("1:7") With Variables? (https://www.excelbanter.com/excel-programming/394099-range-1-7-variables.html)

J@Y

Range ("1:7") With Variables?
 
How would I express Range ("1:7") by replacing the 1 and the 7 with integer
variables?

barnabel

Range ("1:7") With Variables?
 
One simple way (I'm sure other people will present other ways) is:
Range(var1 & ":" & var2)

"J@Y" wrote:

How would I express Range ("1:7") by replacing the 1 and the 7 with integer
variables?


Don Guillett

Range ("1:7") With Variables?
 
try
v1 = 2
v2 = 6
Rows(v1 & ":" & v2).copy

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"J@Y" wrote in message
...
How would I express Range ("1:7") by replacing the 1 and the 7 with
integer
variables?



INTP56

Range ("1:7") With Variables?
 
This demonstrates another way to do this with Excel objects:

Option Explicit

Public Sub RowSelect(WS As Worksheet, intRow1 As Integer, intRow2 As Integer)
Dim rngTest As Range
With WS
Set rngTest = .Range(.Rows(intRow1), .Rows(intRow2))
End With
rngTest.Select
End Sub

Public Sub TestRowSelect()
RowSelect WS:=ThisWorkbook.Worksheets(1), intRow1:=1, intRow2:=7
End Sub

Bob

"J@Y" wrote:

How would I express Range ("1:7") by replacing the 1 and the 7 with integer
variables?


Dana DeLouis

Range ("1:7") With Variables?
 
My preference is to avoid strings if possible.

Sub Demo()
Dim r1 As Long
Dim r2 As Long

r1 = 1
r2 = 7
Rows(r1).Resize(r2 - r1 + 1).Select
End Sub

--
Dana DeLouis


"J@Y" wrote in message
...
How would I express Range ("1:7") by replacing the 1 and the 7 with
integer
variables?





All times are GMT +1. The time now is 11:29 PM.

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