Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default 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/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use Sum() with variable range Jeff Excel Worksheet Functions 4 April 7th 09 05:26 AM
Variable Range James C. Excel Discussion (Misc queries) 3 April 2nd 09 12:41 AM
How to use a variable for a range Jeff Lowenstein Excel Worksheet Functions 1 July 26th 05 02:14 AM
variable range: l just can't get there! ste mac Excel Programming 2 October 27th 03 06:43 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 11:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"