+ Reply to Thread
Results 1 to 9 of 9

Testing a column, change contents

  1. #1
    Registered User
    Join Date
    11-29-2010
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    11

    Testing a column, change contents

    Hello everyone,

    I'm writing a big macro to automate manual workings of a excel sheet that would normally take a good day.

    I'm having trouble figuring this one out - a column named 'account numbers' (Q) should have account numbers in them, which is a ten digit number, beginning with 7 (7 xxx xxx xxx).

    Sometimes it has other information in it, which doesn't match to this rule. In that case, the contents of the field needs to be replaced with 71 000 000 01. In the next row where the contents doesn't match up, it needs to be replaced with 71 000 000 02, and so on.

    This needs to occur until the entire populated column (Q) has been checked and replaced where required - so it stops when it detects and empty field.


    Can anyone point me to the right direction to do this?

    Thanks,
    Daniel
    Last edited by lieb39; 11-29-2010 at 04:04 PM.

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

    re: Testing a column, change contents

    Can you post a small sample workbook?

  3. #3
    Registered User
    Join Date
    11-29-2010
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Macro: Testing a column, change contents

    It's attached.

    I had to take out the data but the columns are copied.

    The first two entries (rows) are OK - but the last two (in red) are the ones that need to be changed to:
    710000001
    710000002
    (and so on)

    The macro would just need to run through the C/S Account Number and do as I described.

    Thanks so much,
    Daniel
    Attached Files Attached Files

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

    Re: Testing a column, change contents

    Here is one approach:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-29-2010
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Testing a column, change contents

    Thank you so much! I've been working on getting this to work for such a long time.

    Thanks again

    Cheers

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

    Re: Testing a column, change contents

    My pleasure.

  7. #7
    Registered User
    Join Date
    11-29-2010
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Testing a column, change contents

    I'm trying to re-use the same code to help me populate a formula into a new column.
    The formula itself is "=RC[-2]*RC[-1]+5.95"

    The Code I'm using is:
    For Each r In Range("W2", Range("W2").End(xlDown))
    r = "=RC[-2]*RC[-1]+5.95"
    Next r
    It runs fine but it fills out the entire sheet down to the last row (and takes forever) unless I break the code. Is it possible to just populate to the last row that has data?

    Thanks,
    Daniel

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

    Re: Testing a column, change contents

    Perhaps you have nothing in W except W2, so this is a better formulation:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-29-2010
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Testing a column, change contents

    Quote Originally Posted by StephenR View Post
    Perhaps you have nothing in W except W2, so this is a better formulation:
    Please Login or Register  to view this content.
    Yep - Googled it and found this:

    Range("W2:W" & Range("A" & Rows.Count).End(xlUp).Row).Formula = "=RC[-2]*RC[-1]+5.95"

    Thanks

+ 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