Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting values from cells in a range 1

Status
Not open for further replies.

MarkGorecki

Technical User
Jul 1, 2004
7
US
Hello,
My code currently allows me to select cells with wich to create a chart. (shown below)
Dim varRange As Variant, RangeSel As Range, Month As Variant
On Error Resume Next
Set varRange = _
Application.InputBox("Select a range of cells:", Type:=8)
If IsObject(varRange) = False Then Exit Sub
MsgBox varRange.Range

I would like to get the value of the first cel in the selected range. I have this:

Month = Range("varRange")(1, 1)

But it does not seem to work. I would like to replace the line:
Selection.Characters.Text = "Month Error Percentage"

with the actual month extraced from the first cell.

Thanks in advance.
 
Hi,

varRange is ALREADY a RANGE!
Code:
   Month = varRange(1,1).Value
I dont know what you want here
Code:
Selection.Characters.Text = "Month Error Percentage"
NOTHING is selected

Do you want this?
Code:
varRange(1,1).Value = "Month Error Percentage"


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Hi Skip,
Sorry about the clarity of my request.

I'm actually asking two questions that are linked.
1. The line
Month = Range("varRange")(1, 1)
does not seem to work. What I wanted to accomplish with this line is to get the value of the first cell of the selected range. In the spreadsheet, "January" is entered in the first cell of the range. I was trying to get Month to = "January".

2. I have another line in the code that has:
Selection.Characters.Text = "Month Error Percentage"
I would like to replace the word "Month" in that line with the Month variable set in question 1.

Thanks,
Mark

 
I would advise against selecting and activating. faq707-4105 How Can I Make My Code Run Faster?
Code:
Selection.Value = Month & " Error Percentage"
I would ALSO advise to use REAL DATES instead of Month Names. Dates can be Custom Formatted to DISPLAY the FULL month name "mmmm", or the ABBREVIATED month "mmm" or the NUMERIC month "mm".

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Something like this ?
Selection.Characters.Text = varRange(1,1).Value & " Error Percentage"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you PH! That was exactly what I needed.

Many of these functions are still new to me and yours and Skips information really helps me to learn. Thanks to both of you.
 
Mark,

Did you read my posts???

I know that I did not put all the pieces together.

:cool:

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Skip,
Yes I did. Looking at code and understanding the output helps a bunch.

Thanks again.
Mark
 
Well if

A = B

and

B = C

then does it not follow that

A = C

???

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top