+ Reply to Thread
Results 1 to 2 of 2

Defining a cell name as a variable

  1. #1
    Registered User
    Join Date
    04-27-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Defining a cell name as a variable

    Hi,

    Is there a way that I can define a variable for the actual cell name?

    I'm trying to automate a process where I'm charting some data in a sheet and in the vba code, I want to select, for example, cells b12:c24 for a scatterplot.

    what I'd like to do is something like this:

    find top cell corresponding to the range of interest (i.e. cell a11 = Mike)... so

    rough code:

    dim xblah1 as string
    dim xblah2 as string
    dim yblah1 as string
    dim yblah2 as string
    dim nm as string

    nm = Mike

    sheets("Data").select

    cells.find(what:=" & nm & "....).Activate ' this activates cell a11 which has the name Mike in it.

    activecell.offset(1,1).select ' this will be cell b12 and the first xValue for a plot
    xblah1 = activecell.name ' now blah should be set to "b12" as its value
    selection.end(xlDown).select ' this will be b24 and the last xvalue
    xblah2 = activecell.name ' xblah2 is set to "b24" as it's value
    activecell.offset(0,1).select ' this will be cell c24 and the yValues for a plot
    yblah2 = activecell.name ' yblah2 is set to "c24" or last yValue for plot
    selection.end(xlUp).Select ' this will be cell c12 and the first yValue
    yblah1 = activecell.name ' yblah1 is set to "c12" or first yValue

    the code doesn't work for activecell.name but because the a11 "Mike" variable will be used to find the starting point in the sheet (there are many more locations with "john", "fred", "joe", etc. where offsetting by 1 row and 1 column will get me to my start point for the data to be plotted...

    thus for plotting the data, I want to do the following:

    ActiveChart.PlotArea.Select
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(5).XValues = "=" & xblah1 & ":" & xblah2 & "
    ActiveChart.SeriesCollection(5).Values = "=" & yblah1 & ":" & yblah2 & "
    ActiveChart.SeriesCollection(5).Name = "=" & nm & "

    and so on...

    Any help would be greatly appreciated.

    Best,

    Mike

  2. #2
    Registered User
    Join Date
    04-27-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Defining a cell name as a variable

    I found the solution if anyone is interested:

    dim blah as string

    range("a1").select
    blah = activecell.address



    this gives a result of $a$1

    Thanks.

    Mike

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1