+ Reply to Thread
Results 1 to 8 of 8

Help with a Macro to find last column of data and paste formulas

  1. #1
    Registered User
    Join Date
    11-03-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    44

    Help with a Macro to find last column of data and paste formulas

    Hello guys,

    I have this table:


    Windows("RECONCILIATION WORKING FILE.xlsx").Activate
    table.JPG



    I am building a macro where I paste data (columns A to E) to a new excel file (thus, columns F and G are blank) and then:

    1. I need to go to the last column with data in row 2 (in this case cell F2) and I add the text: 'New Account'
    2. Then I need to go down one row and paste a formula (in this case cell F3): =IF(OR(LEFT(B3,5)="10099",LEFT(B3,5)="10000"),LEFT(B3,5)&"-"&RIGHT(B3,3),LEFT(B3,2)&"-"&MID(B3,11,7)&"-"&LEFT(B3,5))
    3. Then I need to copy the formula until the last row of data
    4. Then I need to do the same thing for colum G (another text and another formula).

    So far I have this:

    Please Login or Register  to view this content.

    but it doesn't work, it shows a 'compilation error' in the formula part of the formula (''10099'') and it stops.... also, I am not sure it is ok.....

    please could anyone help me out to finish the code?

    thanks!
    Last edited by matador_24; 12-13-2011 at 10:34 AM.

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

    Re: Help with a Macro to find last column of data and paste formulas

    One thing you have to do in VBA is double-up the quotes:
    Please Login or Register  to view this content.
    There may be other issues. A workbook is more useful than a picture.

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Help with a Macro to find last column of data and paste formulas

    I suspect that you are wanting to add a column to your table, at least initially.

    Give this a try, it isn't all necessarily required , but it should show you where to go.
    Please Login or Register  to view this content.
    Last edited by Marcol; 12-12-2011 at 02:12 PM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  4. #4
    Registered User
    Join Date
    11-03-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Help with a Macro to find last column of data and paste formulas

    Thanks a lot guys, that is exactly what I was looking for!

    I really appreciate the help of both!


  5. #5
    Registered User
    Join Date
    11-03-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Help with a Macro to find last column of data and paste formulas

    Hello, just one question.... after the result of the formula, I have to 'auto shape' the column with the formula because the result is long..... what can I add at the end of the code to do so????
    and also, what can I add so that the fill of the 'New account' cell is in blue? (any blue color)

    thanks

  6. #6
    Registered User
    Join Date
    11-03-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Help with a Macro to find last column of data and paste formulas

    A little of help here please

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

    Re: Help with a Macro to find last column of data and paste formulas

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

  8. #8
    Registered User
    Join Date
    11-03-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Help with a Macro to find last column of data and paste formulas

    thanks a lot guys!

+ 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