VBA Macro Help - If cell contains a certain word use this formula

alxn

New Member
Joined
Jul 17, 2023
Messages
14
Office Version
  1. 365
  2. 2021
  3. 2013
Platform
  1. Windows
Hello, I need assistance trying to figure out a way in which a formula will run based on a word within a specific column, and populate results in another column.

EX.
In column A if I have the word "Monday" then this formula will run and populate result in another column
If I have the word "Tuesday" then a different formula will run and populate result in the same column as the others

The formula result will all be populated into the same column

Please let me know if this is possible I would greatly appreciate it.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Please show us a small sample of your data, and expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

Also, when exactly should this VBA code run?
Manually, or automatically when a new value is entered into cell A1?
If automatically, how exactly is cell A1 being updated? Manually, or does it contain a formula?
 
Upvote 0
Kind of depends on how your data is in Column A. If the entire cell will be Monday or Tuesday or other values, this should work:

=IF(FIND("Monday",A2)=1,"Yes Form","No Formula")

Put your formula where the "Yes Form" is at. You can use the "No Formula" for an exception or leave blank to do nothing.
 
Upvote 0
Please show us a small sample of your data, and expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

Also, when exactly should this VBA code run?
Manually, or automatically when a new value is entered into cell A1?
If automatically, how exactly is cell A1 being updated? Manually, or does it contain a formula?
Hello, the code will run manually. I just need need something that will run if only that certain text is there. I'll try XL2BB, and thanks for clarifying on my post.
 
Upvote 0
Kind of depends on how your data is in Column A. If the entire cell will be Monday or Tuesday or other values, this should work:

=IF(FIND("Monday",A2)=1,"Yes Form","No Formula")

Put your formula where the "Yes Form" is at. You can use the "No Formula" for an exception or leave blank to do nothing.
It is 7 different values so lets say Monday-Sunday. Would this still work? I will try it thank you for your input.
 
Upvote 0
If you want to use VBA, I think using a CASE statement would be the cleanest option, instead of nesting an IF statement 7 levels.
See: MS Excel: How to use the CASE Statement (VBA)

If you need help setting it up, please provide more details, i.e. what exactly you want to go where.
 
Upvote 0
If you want to use VBA, I think using a CASE statement would be the cleanest option, instead of nesting an IF statement 7 levels.
See: MS Excel: How to use the CASE Statement (VBA)

If you need help setting it up, please provide more details, i.e. what exactly you want to go where.
1689617624963.png

it would be essentially like this. Lets say if its:
Monday the formula would be "(B2+30)"
Tuesday the formula will be "(B3+30-20)"

Each day will have a separate formula, and the output will be "C"
There is also multiple Mondays and multiple Tuesdays so on and so forth.
 
Upvote 0
I think this might be able to be done with a single lookup formula (no VBA required).

Which version of Excel are you tryng to do this in? You have listed 365, 2021, and 2013, and there are new functions in the later versions that are not available in 2013.

Can you list out for us all 7 different values to add to the dates for each of the days of the week, so we can create the complete formula for you? i.e.
Monday 30
Tuesday 10
...
 
Upvote 0
I think this might be able to be done with a single lookup formula (no VBA required).

Which version of Excel are you tryng to do this in? You have listed 365, 2021, and 2013, and there are new functions in the later versions that are not available in 2013.

Can you list out for us all 7 different values to add to the dates for each of the days of the week, so we can create the complete formula for you? i.e.
Monday 30
Tuesday 10
...
The version of excel is 2021, it's not necessarily like Monday 30. Monday was just the word I used so the Monday would be another word in this case, but the date will remain the same, as well as the formula.
 
Upvote 0
OK, not sure why you are being so vague and not wanting to give the details.
The danger in oversimplifying your question is the answer you get may work for your oversimplified example, but not work on your actual data.
I was really hoping that you could show us a realistic example of your data, formulas, and and expected results.
Without that, we can really only give generic answers.

You should be able to use a NESTED IF statement, as described here: IF function – nested formulas and avoiding pitfalls - Microsoft Support.
The formula could get a little long and cumbersome. There may well be simpler solutions, but without knowing the details I have been asking for, it is very hard to know exactly which ones may work in your particular circumstance.
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,109
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top