+ Reply to Thread
Results 1 to 8 of 8

Code to extend formula on changing ranges

  1. #1
    Registered User
    Join Date
    12-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Code to extend formula on changing ranges

    Hi Experts,

    I am pretty new to VBA, I am trying to automate a task where I have to remove duplicates from my table, sort the table, insert a formula and change formula to consider all the cells within the table. So far I was able to complete 2/4 steps and was able to create a formula I am trying my best however I am stuck at one point where I have to "extend" formula in one cell to take account of all the newly added rows because next time when I paste the new table in my macro it may have more/less rows and based upon that I have to change my formula which is kept in one cell.

    I have also attached my working macro. I have added a separate tab called "Example" where I have outlined my steps. I am thinking the future process to be

    1. Paste the data table in "Input" Sheet of macro
    2. Run the macro and have result ready in cell F5 (Could be any cell) of "Input" sheet
    3. I also need to copy and paste this result in a single cell of master table's corresponding row however I do not bother anyone about this step - I will manage it

    If you paste the table (A3:C14) from "Example" sheet to A1 of "Input" sheet and run the macro1 you will see that I have removed duplicates+sorted the table based on column A. Can somebody suggest a code that would have updated formula in F5?

    I have very basic knowledge of programming

    Thanks for your time.
    Best,
    Bunty
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Code to extend formula on changing ranges

    Use this code, instead of a msgbox, make a range equal "s"

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Code to extend formula on changing ranges

    Thank you soo much Dave, it worked like a charm I really really appreciate your help!!!!!

    I have changed the code as per your suggestion and I have the output in "Output" sheet cell A2. Now I am left with conditional format, I need to color just "AND"/"OR" in this cell, Is it possible? I dont see any option to attach the revised macro hence writing the final output statement below.


    Monday OR Tuesday AND Thursday OR Wednesday OR Friday AND Saturday OR Sunday


    Best,
    Bunty

  4. #4
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Code to extend formula on changing ranges

    Not sure you can do this with CF but this macro will do it on the contents of your cell i9. You can change the bold and the colours you want accordingly

    Please Login or Register  to view this content.
    Happy with my advice? Click on the * reputation button below

  5. #5
    Registered User
    Join Date
    12-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Code to extend formula on changing ranges

    Thank you so much Crooza, it is working fine except a situation where there is OR in the sentence (Which should't be highlighted) I understand it's tricky but can we instruct our program to exact match "OR" and "AND" and only color those?

    I am facing below problem, you will see that it is also coloring the OR of COLOR/AND of CANDY

    COLOR AND CANDY OR FUN

    I appreciate your time to look in to this.
    Best
    Bunty

  6. #6
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Code to extend formula on changing ranges

    Yes I didn't anticipate that in the example plus I didn't realise you would spell colour wrong

    Try this instead

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Code to extend formula on changing ranges

    I apologize for that, I should have used a better example.

    Just wanted to let you know this time it worked perfectly, I really appreciate your time. Cant thank you much. You are a life savior. Thank you thank you thank you

    Have a great weekend!

    Best,
    Bunty

  8. #8
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Code to extend formula on changing ranges

    Great. I'm glad it worked.

+ 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. A Challenge:Extend Code of a button to remove the Formula of the Saved Page and lock
    By ronettes in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2014, 06:01 AM
  2. How to extend a changing multi cell array formula down a column.
    By Patrician in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-12-2013, 07:07 PM
  3. Code for vlookup with changing ranges
    By trier in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-24-2012, 04:31 PM
  4. Changing ranges of current code
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-14-2011, 01:42 PM
  5. Changing ranges of code
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-19-2011, 05:21 AM
  6. formula with changing cell ranges
    By db in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-06-2005, 07:05 PM
  7. formula with changing cell ranges
    By Grant in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-23-2005, 02:05 PM

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