+ Reply to Thread
Results 1 to 9 of 9

Macro to match criteria and apply algebra operation

  1. #1
    Forum Contributor
    Join Date
    04-19-2016
    Location
    Michigan
    MS-Off Ver
    15.0
    Posts
    130

    Macro to match criteria and apply algebra operation

    Good afternoon,

    I am trying to simplify my work by reducing repetition.

    Basically, I have to sift through hundred of lines to match if Column A = "A" and Column B = "B", then change the price with a 10% tax mark up.

    Since this file is generated daily, it is important to have a macro, rather than formulas, as I need an operation to change the price (where the 2 conditions are met) values in one instance and keep all the cells exactly where they are for further manual calculations.

    ThankszF2FULA.png

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Macro to match criteria and apply algebra operation

    Try this for starters.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Contributor
    Join Date
    04-19-2016
    Location
    Michigan
    MS-Off Ver
    15.0
    Posts
    130

    Re: Macro to match criteria and apply algebra operation

    Thanks - it seems to work very well!

    I am trying to edit the code to match with my spreadsheet structure and it seems like it is not moving to the next test very well. Basically my real spreadsheet has a few headers, and A and B now are on comlumn D and E, with price on column G. So I got the following code. If I copy and paste an example to the first row it would work but it would not go through the whole list.

    Thanks much!
    Please Login or Register  to view this content.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Macro to match criteria and apply algebra operation

    Please Login or Register  to view this content.
    Change the 1 to the rownumber where your data starts (just below headers)
    Also make sure there are no empty rows in between your data.

  5. #5
    Forum Contributor
    Join Date
    04-19-2016
    Location
    Michigan
    MS-Off Ver
    15.0
    Posts
    130

    Re: Macro to match criteria and apply algebra operation

    There will be empty spaces in between - is there away to circumvent this or I would have to write the same code for i=n, with the nth row being the next line after the gap.

    Thanks!

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Macro to match criteria and apply algebra operation

    How about this ?

    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,554

    Re: Macro to match criteria and apply algebra operation

    No loop
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    04-19-2016
    Location
    Michigan
    MS-Off Ver
    15.0
    Posts
    130

    Re: Macro to match criteria and apply algebra operation

    Thanks - both ways work perfectly!

    One last request? Is there away for me to run a MsgBox to report how many calculations were made (how many times the criteria were matched and calculations were done)?

    My final customized code is as follows - to run calculations for 2 scenarios:

    Please Login or Register  to view this content.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,554

    Re: Macro to match criteria and apply algebra operation

    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)

Similar Threads

  1. Replies: 4
    Last Post: 11-01-2016, 03:28 PM
  2. Replies: 3
    Last Post: 08-25-2014, 08:04 PM
  3. Replies: 0
    Last Post: 09-21-2013, 09:03 PM
  4. How to apply if condition for the autofilter criteria(excel VBA Macro)
    By chakravarthysm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2013, 09:32 AM
  5. Loop to Match Criteria on Two Sheets and Apply Conditional Format
    By flindy87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2013, 04:06 AM
  6. Apply Criteria Based Row Macro in Multiple Sheet
    By liarliar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-07-2008, 05:53 AM
  7. Macro to apply several conditional formatting criteria
    By useR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2005, 12:05 PM

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