Consulting

Results 1 to 12 of 12

Thread: get cell address without the $'s

  1. #1

    get cell address without the $'s

    Hello All,

    I've been programming for a few years now but have never used Excel VBA until a couple days ago when I was asked to automate some processes.

    I'm trying to create a string variable that contains the name of the cell (eg. A4, AB456, etc.) I will then call on it later to go back to that point
    using Range(variableName).Select

    I have found .Address, but when I call it instead of giving me A4 it gives me $A$4.

    So I have 2 questions

    1) Is there some other function I can call that will give me the address I'm wanting?
    2) If not, is there a way I can manipulate the string so that I can remove the $'s? I have tried replace but I'm afraid I keep getting the syntax wrong.

    thanks for your help!

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    To remove the dollars use this syntax... Selection.Address(0, 0)
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    For more info, check the Address Property in VBA Help. Note that this is not installed by default.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    fantastic!

    thanks for the quick replies.

    this is exactly what I needed.

    The only other thing I'm not sure of right now is making some sort of progress form..I was wanting to make a form that was shown as soon as the macro started with hidden labels that would appear at different points in the macro execution such as:

    querying database...
    updating spreadsheet with document types...
    etc..

    When I made a form and used the form1.Show command, it halted the macro operations, however...is there a property of the form that will let it show while the macro continues to run, updating it as I hit key points in the macro (by simply making label1.Visible=True, label2.Visible=True..etc)

    thanks again!

  5. #5
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Do a search thru the KB with the search word "progress" for some examples
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by greymalkin
    The only other thing I'm not sure of right now is making some sort of progress form..I was wanting to make a form that was shown as soon as the macro started with hidden labels that would appear at different points in the macro execution such as:

    querying database...
    updating spreadsheet with document types...
    etc..

    When I made a form and used the form1.Show command, it halted the macro operations, however...is there a property of the form that will let it show while the macro continues to run, updating it as I hit key points in the macro (by simply making label1.Visible=True, label2.Visible=True..etc)

    thanks again!
    When using a progress form, one appraoch is to initiate the working macro from within the userform, aomething akin to

    Show form
    Setup PB
    Start macro
    do a bit
    update form PB
    do some more
    update form PB
    etc.
    End macro
    Unload form

    or else use a modeless form and DoEvents, nice example here

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    An altrenative approach could be to set a "bookmark" --


    Dim rBackToHere as Range
    ....

    Set rBackToHere = Selection
    ....

    rBacktoHere.Select

  8. #8
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Why do you need to 'go back'?

    Generally you don't need to select/activate, so in theory you should never go away.

    PS What's the problem with the $ anway?

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Norie --

    The OP's example was

    "I'm trying to create a string variable that contains the name of the cell (eg. A4, AB456, etc.) I will then call on it later to go back to that point
    using Range(variableName).Select"

    so I was trying to stay within the intent of the question.

    Nothing wrong with absolute references ($A$4, etc.) and no need to Select it for most things

    In addition to saving the address in a string and then using Range (string) to Select it, you could also save the cell as a range object and manipulate it directly. -- Just a thought about another way

  10. #10
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Paul

    I'm not contradicting your's or anyone else's suggestions, I'm just trying to point that what the OP is doing probably isn't needed in the first place.

    If something isn't actually needed I would suggest it's not actually done.

  11. #11
    VBAX Newbie
    Joined
    Jun 2017
    Posts
    1
    Location

    ...as VBA intended

    how about just .address(false,false) which is the correct programmatic way to handle it

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    10 year old post
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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