Variable in range

M

morry

Can a variable be put into a range? If so could somebody tell me wha
is wrong with this code. (Cell B6 hold a numeric value.)

Dim x As Range

x = Range("B6").Value

Rows("1:x").Select
Selection.Insert Shift:=xlDown

Thank you for the help

Morr
 
P

pvictor

Moryy,

In "1:x", you really want the value of x not "x" itself. Also, x should be Dim-ed as an Integer (Long?) and not a Range.

Change code to something like the following.

Hope this helps.

Victor


---------------------------------------------
Dim x As Integer ' Range??
Dim sRange as string

x = Range("B6").Value
sRange = "1" & ":" & cstr(x)
Rows(sRange).Select
Selection.Insert Shift:=xlDown
 
D

Dana DeLouis

Maybe just another option:

Dim x As Long
x = Range("B6").Value
Rows(1).Resize(x).Insert

HTH
Dana DeLouis
 
Top