Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Need help using a variable in Range command

Try this out - I think it is what your trying to do - one
mistake was putting a variable in quotes (this makes it
appear as a string)

Sub Sta1CycleTimeFill()
Dim Sta1EndRangeValue As Integer

Sta1EndRangeValue = Range("g2").Value
MsgBox Sta1EndRangeValue
Sta1EndRange = "d" & Sta1EndRangeValue
MsgBox Sta1EndRange
Range("d2", Sta1EndRange).Select
'Range("D2").Offset(Sta1EndRange, 0).Select
'Selection.Copy
'Range("I2").Select
'ActiveSheet.Paste


End Sub
-----Original Message-----

Hello,

I am trying to select a variably sized range in column D

using the
following code:

Sub Sta1CycleTimeFill()
Dim Sta1EndRangeValue As Integer

Sta1EndRangeValue = Range("g2").Value
MsgBox Sta1EndRangeValue
Sta1EndRange = "d" & Sta1EndRangeValue
MsgBox Sta1EndRange
Range(d2, "Sta1EndRange").Select
'Range("D2").Offset(Sta1EndRange, 0).Select
'Selection.Copy
'Range("I2").Select
'ActiveSheet.Paste


End Sub

With the current data that I have the value in G2 is 347,

when I run
the macro the first message box shows 347 and the second

message box
shows d347, but then I get a Run-time error '1004':
Method 'Range' of object '_Global' failed for the Range

(d2,
"Sta1EndRange").Select line.

How do I go about making the first and last cells in the

range command
be variables? After this data is copied & pasted to I2 I

then need to
find the next variably sized chunk and copy and paste to

J2 and so on
for a total of 7 times. I know how big each range is

because in cells
G2:G8 I have the formulas
=COUNTIF(A:A, "sta1")
=COUNTIF(A:A, "sta2")
=COUNTIF(A:A, "sta3")
=COUNTIF(A:A, "sta4")
=COUNTIF(A:A, "sta5")
=COUNTIF(A:A, "sta6")
=COUNTIF(A:A, "sta7")
respectively.

Thank you.


--
cbeebe
----------------------------------------------------------

--------------
cbeebe's Profile: http://www.excelforum.com/member.php?

action=getinfo&userid=13601
View this thread:

http://www.excelforum.com/showthread...hreadid=275636

.

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
Variable Or Command str83dgeboi Excel Worksheet Functions 7 November 13th 08 07:42 PM
SUM command using variable sheets IanC Excel Worksheet Functions 3 May 18th 07 11:56 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Variable usage in Range Command DavidC[_2_] Excel Programming 2 May 27th 04 03:51 AM
variable 'open' command Walt[_2_] Excel Programming 3 July 27th 03 09:06 PM


All times are GMT +1. The time now is 07:19 PM.

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

About Us

"It's about Microsoft Excel"