+ Reply to Thread
Results 1 to 9 of 9

Using named cells in VBA

  1. #1
    Registered User
    Join Date
    08-07-2020
    Location
    The Villages Florida
    MS-Off Ver
    2013
    Posts
    21

    Using named cells in VBA

    I need some help.

    H5 cell has "PELIC" in it. When it gets Concatenated with P or R I should get PELICP and PELICR which are the names of cells containing numbers.

    In Excel this line is in cell G5
    =F5-INDIRECT(CONCATENATE(H5 & "P"))-INDIRECT(CONCATENATE(H5 & "R"))
    It runs just fine

    Now I want to use this line in VBA Macro instead
    Range("G5").Value = F5-INDIRECT(CONCATENATE(H5 & "P"))-INDIRECT(CONCATENATE(H5 & "R"))
    But it does not work, I get this error

    Compile error
    Expected list seperator or )

    Can you help me with this

  2. #2
    Forum Contributor Dante Amor's Avatar
    Join Date
    07-24-2020
    Location
    MEXICO
    MS-Off Ver
    Excel 2013
    Posts
    212

    Re: Using named cells in VBA

    Hi and welcome to ExcelForum.

    Try this:

    Please Login or Register  to view this content.

  3. #3
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: Using named cells in VBA

    Try this...

    Please Login or Register  to view this content.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Using named cells in VBA

    What's in F5?
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Using named cells in VBA


    Quote Originally Posted by pumper View Post
    Now I want to use this line in VBA Macro instead
    Range("G5").Value = F5-INDIRECT(CONCATENATE(H5 & "P"))-INDIRECT(CONCATENATE(H5 & "R"))
    But it does not work
    Try [G5] = [F5-INDIRECT(CONCATENATE(H5&"P"))-INDIRECT(CONCATENATE(H5&"R"))]

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Using named cells in VBA

    Not a direct answer to the problem, but why is the CONCATENATE formula being used in this way where instead of , to separate the various texts to be concatenated the & is used to concatenate the texts into a single argument that actually does not require concatenation?

    Either it's

    CONCATENATE(H5 , "P")

    or simply

    H5 & "P"
    Cheers
    Andy
    www.andypope.info

  7. #7
    Registered User
    Join Date
    08-07-2020
    Location
    The Villages Florida
    MS-Off Ver
    2013
    Posts
    21

    Re: Using named cells in VBA

    Thank you for all your help.
    All 3 of the suggestions worked, I will use the one by Dante Amor. It's the fastest to write.

    As far as what's in F5, just a number

    Why was I using CONCATENATE(H5 , "P") etc. The original formula was in a cell not VBA, that's the way I was told to do it.

    I am new to this as you can see, can you explain the use of [ ]?

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Using named cells in VBA


    See the VBA help of the powerful Evaluate method …

  9. #9
    Forum Contributor Dante Amor's Avatar
    Join Date
    07-24-2020
    Location
    MEXICO
    MS-Off Ver
    Excel 2013
    Posts
    212

    Re: Using named cells in VBA

    All 3 of the suggestions worked, I will use the one by Dante Amor. It's the fastest to write.
    I'm glad to help you. Thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Mapping Named Cells to Named Cells in Separate Workbooks
    By sb212410 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2018, 02:43 PM
  2. [SOLVED] Compare cells to named range and create new sheets using related named range
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-10-2015, 03:35 PM
  3. Named Cells
    By BobBlooms in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-10-2012, 12:39 PM
  4. Named Cells
    By jartzh in forum Excel General
    Replies: 1
    Last Post: 02-16-2009, 11:02 AM
  5. [SOLVED] Excell named cells or labeled cells question
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-25-2006, 12:20 PM
  6. [SOLVED] Excel named cells or labeled cells question
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-25-2006, 11:45 AM
  7. Replies: 1
    Last Post: 06-03-2006, 10:55 PM

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