ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Help make a macro variable (https://www.excelbanter.com/excel-discussion-misc-queries/179447-help-make-macro-variable.html)

Brad

Help make a macro variable
 
The following macro works - how can I make it so thate the numbers can be
variable.

Sub test3()
shtGPA9D.Rows("195:198").Insert
End Sub

I would like to have something like the following
Sub test3()
dim r as integer
r = 195
shtGPA9D.Rows(r:r+3).Insert
End Sub


Brad

Help make a macro variable
 
Why does this work with "r" defined as long and not with integer?

Sub test3()
Dim r As Long
r = 195
shtGPA9D.Rows(r & ":" & r + 3).Insert
End Sub

"Brad" wrote:

The following macro works - how can I make it so thate the numbers can be
variable.

Sub test3()
shtGPA9D.Rows("195:198").Insert
End Sub

I would like to have something like the following
Sub test3()
dim r as integer
r = 195
shtGPA9D.Rows(r:r+3).Insert
End Sub


Rick Rothstein \(MVP - VB\)[_199_]

Help make a macro variable
 
It works for me whether 'r' is defined as Long or Integer.

Rick


"Brad" wrote in message
...
Why does this work with "r" defined as long and not with integer?

Sub test3()
Dim r As Long
r = 195
shtGPA9D.Rows(r & ":" & r + 3).Insert
End Sub

"Brad" wrote:

The following macro works - how can I make it so thate the numbers can be
variable.

Sub test3()
shtGPA9D.Rows("195:198").Insert
End Sub

I would like to have something like the following
Sub test3()
dim r as integer
r = 195
shtGPA9D.Rows(r:r+3).Insert
End Sub



Jim Thomlinson

Help make a macro variable
 
The initial code posted Did not have the colon in Quotes. That's the
difference...
--
HTH...

Jim Thomlinson


"Brad" wrote:

Why does this work with "r" defined as long and not with integer?

Sub test3()
Dim r As Long
r = 195
shtGPA9D.Rows(r & ":" & r + 3).Insert
End Sub

"Brad" wrote:

The following macro works - how can I make it so thate the numbers can be
variable.

Sub test3()
shtGPA9D.Rows("195:198").Insert
End Sub

I would like to have something like the following
Sub test3()
dim r as integer
r = 195
shtGPA9D.Rows(r:r+3).Insert
End Sub



All times are GMT +1. The time now is 02:33 PM.

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