+ Reply to Thread
Results 1 to 6 of 6

Can't concatenate a cell address

Hybrid View

  1. #1
    Registered User
    Join Date
    03-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Can't concatenate a cell address

    Ah, for some reason I had to use trim. Null terminator maybe?

    strCellValue = Range("A" + Trim(Str(intCount))).Value

    Cheers,
    J


    Quote Originally Posted by JohnSidney View Post
    Hiya,

    This seems odd. I want to concatenate a cell address but I get an error: Run-time error '1404'; Method 'Range' of object '_Global' failed.

    here's my code:
    dim intCount as integer

    intCount = 2
    strCellValue = Range("A" + Str(intCount)).Value 'This throws the error

    strCellValue = Range("A2").Value 'This works!

    I tried changing my variable type to variant but no such luck. Any ideas?

    Cheers,
    John

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

    Re: Can't concatenate a cell address

    FYI, here is what the help says about the STR function.

    Remarks

    When numbers are converted to strings, a leading space is always reserved for the sign of number. If number is positive, the returned string contains a leading space and the plus sign is implied.

    Use the Format function to convert numeric values you want formatted as dates, times, or currency or in other user-defined formats. Unlike Str, the Format function doesn't include a leading space for the sign of number.

    Note The Str function recognizes only the period (.) as a valid decimal separator. When different decimal separators may be used (for example, in international applications), use CStr to convert a number to a string.
    So your problem is leading space.
    Try this in the immediate window to see the difference.
    ?">A" + Str(1);"<",">A";CStr(1);"<"
    Cheers
    Andy
    www.andypope.info

+ 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