Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Select variable range

Hi all,

I am struggling with the correct syntax for the above. I am writing a macro
to create a chart from a list of monthly data. I want the user to be able to
select the first and last months (will usually be 12 months apart). I have
got as far as finding the first and last variables, but can't work out how to
select the cells from one to the other:

'Financials
Dim Message, Title, Default, MyValue
Message = "Enter first month" ' Set prompt.
Title = "First Month" ' Set title.
Default = "Jun-06" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)

Dim FirstMonth, LastMonth, chartdata As Range
Dim ws As Worksheet
With Worksheets("Gas").Range("a:a")
Set FirstMonth = .Find(MyValue, LookIn:=xlValues)
If Not FirstMonth Is Nothing Then
MsgBox FirstMonth
FirstMonth.Select
Else
MsgBox "Value not available", vbOKOnly, "Error"
Exit Sub
End If
End With

Message = "Enter last month" ' Set prompt.
Title = "Last Month" ' Set title.
Default = "Jun-07" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)

With Worksheets("Gas").Range("a:a")
Set LastMonth = .Find(MyValue, LookIn:=xlValues)
If Not LastMonth Is Nothing Then
'Last required cell in range
LastMonth.Offset(0, 2).Select
'This is where I want to selct from FirstMonth to
LastMonth.Offset(0, 2)
'and set the range as chartdata (I think?!)
chartdata.Select

Exit Sub
End If
End With

Please help...!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Select variable range

Forget about it:

Range(FirstMonth, LastMonth.Offset(0, 2)).Select

"ewan7279" wrote:

Hi all,

I am struggling with the correct syntax for the above. I am writing a macro
to create a chart from a list of monthly data. I want the user to be able to
select the first and last months (will usually be 12 months apart). I have
got as far as finding the first and last variables, but can't work out how to
select the cells from one to the other:

'Financials
Dim Message, Title, Default, MyValue
Message = "Enter first month" ' Set prompt.
Title = "First Month" ' Set title.
Default = "Jun-06" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)

Dim FirstMonth, LastMonth, chartdata As Range
Dim ws As Worksheet
With Worksheets("Gas").Range("a:a")
Set FirstMonth = .Find(MyValue, LookIn:=xlValues)
If Not FirstMonth Is Nothing Then
MsgBox FirstMonth
FirstMonth.Select
Else
MsgBox "Value not available", vbOKOnly, "Error"
Exit Sub
End If
End With

Message = "Enter last month" ' Set prompt.
Title = "Last Month" ' Set title.
Default = "Jun-07" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)

With Worksheets("Gas").Range("a:a")
Set LastMonth = .Find(MyValue, LookIn:=xlValues)
If Not LastMonth Is Nothing Then
'Last required cell in range
LastMonth.Offset(0, 2).Select
'This is where I want to selct from FirstMonth to
LastMonth.Offset(0, 2)
'and set the range as chartdata (I think?!)
chartdata.Select

Exit Sub
End If
End With

Please help...!!

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
Select a variable range Bluecat Excel Worksheet Functions 7 January 13th 09 01:24 AM
Select a variable range Eduardo Excel Programming 7 August 8th 07 01:46 PM
Use a Variable to select a range Connie Excel Discussion (Misc queries) 3 October 19th 06 05:48 PM
select a variable range evil baby[_15_] Excel Programming 4 March 8th 06 08:38 PM
Select a Range Through a Variable GoFigure[_9_] Excel Programming 3 December 6th 05 01:02 PM


All times are GMT +1. The time now is 09:25 PM.

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"