+ Reply to Thread
Results 1 to 16 of 16

A loop to read one cell and print to another

  1. #1
    Registered User
    Join Date
    01-25-2010
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    A loop to read one cell and print to another

    Hi guys,

    I am trying to program a loop in Excel VBA to read the first two characters of a cell in column A and, depending on the characters returned, to print something else in column B, then move to the next row up. What I have so far below is pieced together from little insights from over the web, but currently it does nothing. Not even error messages. It has more fields (if "XX" > print blah blah) but they are all the same, so only the first two iterations are shown here for clarity.

    Please Login or Register  to view this content.
    If you can see what is wrong with this code, or indeed, if you have a better idea for how I can tackle this problem, I would really appreciate hearing from you.
    Last edited by maruchi; 01-26-2010 at 09:07 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: A loop to read one cell and print to another

    maruchi: please add code tags (#) as per forum rules.

  3. #3
    Registered User
    Join Date
    01-25-2010
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: A loop to read one cell and print to another

    Tags added. Sorry about that.

    Does this mean a Forum Guru is looking at my request for help? *hopeful face*

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: A loop to read one cell and print to another

    You still don't appear to have added them...
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    01-25-2010
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: A loop to read one cell and print to another

    "left function" , if loops , macro , vba

    ...am I missing something?

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: A loop to read one cell and print to another

    Based on what you said you wanted the code to do, rather than what it appears to be trying to do, I think you want this:
    Please Login or Register  to view this content.
    Note: the above is what was meant by code tags!

  7. #7
    Registered User
    Join Date
    01-25-2010
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: A loop to read one cell and print to another

    Ahhh

    Now I understand. Sorry about that.

    I am fiddling with that in my macro now.

    Cheers,
    Maru

  8. #8
    Registered User
    Join Date
    01-25-2010
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: A loop to read one cell and print to another

    I adjusted the code to suit my sheet...and it worked! Once...now it has stopped working and isn't throwing up any error messages.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-25-2010
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: A loop to read one cell and print to another

    Nevermind. Seems to have sorted itself out.

    Cheers romper!

  10. #10
    Registered User
    Join Date
    07-19-2011
    Location
    New Jersey US
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: A loop to read one cell and print to another

    Sorry to reopen a closed thread.

    I tried to use romperstomper's and when I use the code the macro only edits the first line and I am not receiving any errors as it does not move to the next line.

    To test the code I created an Excel sheet with values in Column A with the same first two letters in the macro.

    Do I have to modify the macro for excel 2007.

    Thanks,

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: A loop to read one cell and print to another

    The code looks at column L to determine how many rows to process - did you adjust that?

  12. #12
    Registered User
    Join Date
    07-19-2011
    Location
    New Jersey US
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: A loop to read one cell and print to another

    Thank You for the quick reply.

    I changed the range value from L500 to A6 because there are 6 values in Column A that I want to process.

    I also tried to set Range(A1:A6) and that did not work either.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: A loop to read one cell and print to another

    Change this:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    07-19-2011
    Location
    New Jersey US
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: A loop to read one cell and print to another

    I changed it and I now I get no output to cell B.

  15. #15
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: A loop to read one cell and print to another

    Then I need to see the exact code you are using or, preferably, a sample workbook.

  16. #16
    Registered User
    Join Date
    07-19-2011
    Location
    New Jersey US
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: A loop to read one cell and print to another

    Thank you for the help. After you said about changing the intLastRow I tried different combinations and this works:

    Code:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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