![]() |
Variable in range
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 -- Message posted from http://www.ExcelForum.com |
Variable in range
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 ---------------------------------------------- "morry " wrote: Can a variable be put into a range? If so could somebody tell me what 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 Morry --- Message posted from http://www.ExcelForum.com/ |
Variable in range
Maybe just another option:
Dim x As Long x = Range("B6").Value Rows(1).Resize(x).Insert HTH Dana DeLouis "morry " wrote in message ... Can a variable be put into a range? If so could somebody tell me what 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 Morry --- Message posted from http://www.ExcelForum.com/ |
All times are GMT +1. The time now is 12:29 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com