VBA if string is found then perform calculation in different column

Samgrewal

New Member
Joined
Jan 11, 2022
Messages
2
Office Version
  1. 2010
Platform
  1. Windows
Hi,

I am new to VBA and wondering what the best way to do this would be :
if unit by column contains SP then grab price and divide it by 10 in the updated price field. If it is something else, do nothing.
Is it best to do this as an array function or go through the cells until you reach the end and just offset to get the desired value in the updated price column?

IDUnit ByPriceCostupdated price
1SP105
2UN61
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Any particular reason why you want to use vba? Why not

=IFERROR(IF(FIND("SP",B2)>0,C2/10),0)
or
=IFERROR(IF(FIND("SP",B2)>0,C2/10),"") in updated price column?
 
Upvote 0
Any particular reason why you want to use vba? Why not

=IFERROR(IF(FIND("SP",B2)>0,C2/10),0)
or
=IFERROR(IF(FIND("SP",B2)>0,C2/10),"") in updated price column?
The IT person runs a report off a scheduler every morning. There’s about 20 worksheets that’s are similar just for different branches of our company. I will need to run this type of formula for each worksheet. I thought it would be easier to just copy and paste the vba code.
 
Upvote 0
Not sure what you're describing.
The workbook/sheet gets replaced every day? Then your code would be lost anyway.
A range is cleared and populated every day? Then the formula will stay since it would be outside the range.
If a workbook gets replaced every day then you'll need to run your code from somewhere else - more complicated.
If the sheets get replaced every day, you'll need code at the workbook level.

Just my opinion but repeatedly copying/pasting code would be a non-starter for me.
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

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