+ Reply to Thread
Results 1 to 7 of 7

CStr should work but doesn't, any ideas?

  1. #1
    Registered User
    Join Date
    03-29-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2003
    Posts
    9

    CStr should work but doesn't, any ideas?

    When I 'step' through this, I can see that the right side of the "=" works fine, but the left side doesn't. I'm puzzled!!!


    For i = 2 To 5 Step 25
    Range("P" + CStr(i)) = Range("A" + CStr(i + 13))
    Range("Q" + CStr(i)) = Range("B" + CStr(i + 13))
    Range("R" + CStr(i)) = Range("D" + CStr(i + 13))
    Range("S" + CStr(i)) = Range("A" + CStr(i + 34))
    Range("T" + CStr(i)) = Range("B" + CStr(i + 34))
    Range("U" + CStr(i)) = Range("C" + CStr(i + 34))
    Range("V" + CStr(i)) = Range("K" + CStr(i + 26))
    Range("W" + CStr(i)) = Range("D" + CStr(i + 23))
    Range("X" + CStr(i)) = Range("I" + CStr(i + 18))
    Range("Y" + CStr(i)) = Range("G" + CStr(i + 24))
    Next i

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: CStr should work but doesn't, any ideas?

    Hi there,

    Please Login or Register  to view this content.

    Untested, and difficult to be certain without more information, but maybe:

    Please Login or Register  to view this content.

    Hope this helps,

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    03-29-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: CStr should work but doesn't, any ideas?

    Quote Originally Posted by Greg M View Post
    Hi there,

    Please Login or Register  to view this content.

    Untested, and difficult to be certain without more information, but maybe:

    Please Login or Register  to view this content.

    Hope this helps,

    Regards,

    Greg M
    Thanks Greg, but that didn't do it. As I said the right side is perfect but on the left it's not doing the addition.

  4. #4
    Registered User
    Join Date
    03-29-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: CStr should work but doesn't, any ideas?

    It's working, thank you.

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,963

    Re: CStr should work but doesn't, any ideas?

    Range("P" + CStr(i)) = Range("A" + CStr(i + 13)) ===>
    Cells(i,"P").Value = Cells(i + 13, "A").Value, ...
    Ben Van Johnson

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,509

    Re: CStr should work but doesn't, any ideas?

    I think you should be using ampersand ( & ) on both sides rather than plus ( + ). And I don't think you need CStr at all.

    Range("P" & i) = Range("A" & (i + 13))


    How does this work: For i = 2 To 5 Step 25
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: CStr should work but doesn't, any ideas?

    Hi again,


    but on the left it's not doing the addition


    It's not "addition", it's concatenation - thats why an Ampersand (&) is more appropriate.


    If your "i" variable is an integer (not obvious from your code) you shouldn't need to use the CInt function.


    Regards,

    Greg M
    Last edited by Greg M; 05-09-2023 at 06:23 PM. Reason: Typo corrected

+ 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. code doesnt work if the filepath is too long? any ideas
    By MP1989 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-06-2019, 09:13 PM
  2. Solver wont work in 2010, any other ideas
    By gary98208 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-13-2014, 02:26 PM
  3. Need ideas for a Complicated Excel Formula which needs work
    By ACrossley1 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-05-2014, 07:46 PM
  4. [SOLVED] any Ideas Why this INDEX MATCH formula doesnt work ?
    By ecelaras in forum Excel General
    Replies: 13
    Last Post: 11-30-2012, 06:55 AM
  5. [SOLVED] IF test doesnt work to match data. Any ideas?
    By MyComputerGuy in forum Excel General
    Replies: 7
    Last Post: 11-12-2011, 04:23 PM
  6. [SOLVED] This code won't work, any ideas?
    By Santiago in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2005, 10:05 AM
  7. [SOLVED] Vlookup won't work, any other ideas?
    By Huw in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-18-2005, 10:06 AM

Tags for this Thread

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