+ Reply to Thread
Results 1 to 3 of 3

Change Macro Formula

  1. #1
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Change Macro Formula

    Hi,

    I created macro named “Works” within the workbook “ContinueExample.xlsm” attached to this post that populates a Date Value in cell “P2” to the very last cell in Column P based on the last row with data in worksheet “strSName”.

    The way the macro knows which Date Value to populate the “P” cells with is based on the values found in Column N beginning with cell “N2” in worksheet “strSName” and the range values beginning with M2 to the last cell in Column N in worksheet “strLName”.

    Here is an example of how the macro works:
    In cell “N2” you find the value “Honda” in worksheet “strSName”, what the macro will do is look up the value “Honda” beginning with cell “M2” in worksheet “strLName” and if it exists, it will populate cell “P2” in worksheet “strSName” with the corresponding Date Value which in this case would be “N2” of sheet “strLName”, but if it doesn’t exist it will leave the cell blank.

    If you execute the macro it will do the same thing for the rest of the cells in Column N in worksheet “strSName” and then determine which Date Value to assign it in Column P cells.

    The macro runs fine, but it is not flexible enough. What I mean is that the VLOOKUP formula that I am using right now within the VBA code is limited to 6 rows (not counting row 1 which contains row titles) which are based on the number of rows in worksheet “strLName”. For this simple example I obviously know the number of rows in worksheet “strLName”, but going forward this will not be the case. The number of rows within worksheet “strLName” can vary and I don’t want to manually change this every time I execute this macro. I need some help with my VLOOKUP formula found within the macro to account for this row change.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Change Macro Formula

    Have the VLOOKUP formula search the entire column. The worksheet function has a built-in capability to only search within the used range when the entire column is specified. So it doesn't affect performance to specify the entire column.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Change Macro Formula

    AlphaFrog,

    That did the trick! Thank you for your time.

    - BC

+ 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. Macro to change formula to value
    By graiggoriz in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-28-2014, 12:39 PM
  2. Got a formula I would like to change into a macro.
    By tripey in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-22-2012, 10:49 AM
  3. Change formula macro
    By sirohiv in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-15-2011, 08:39 AM
  4. Macro to change formula
    By yogesh thakker in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-15-2010, 10:35 AM
  5. Macro to Change Formula
    By floridagunner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2007, 09:59 AM

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