Need to add a character to a cell based on another cell criteria- VBA

TsarMarkI

New Member
Joined
Aug 14, 2019
Messages
20
Hey excel gurus,

I need help creating a VBA macro that will add characters to end of text in a cell based on criteria being met in another cell. This data is cleared and copied over daily, so I need a VBA solve if possible. For example:

Cell B5 contains the text "Planned Downtime"
Cell D5 contains the name of test equipment, in this case "Test1"
Would need the macro to add a "-P" on the end of the text in cell D5 whenever cell B5 has the text "Planned Downtime", so that it would look as so: "Test1-P"

My range for this data runs from B5:B50, and D5:D50. Any help would be greatly appreciated!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about
VBA Code:
Sub TsarMarkl()
   With Range("D5:D50")
      .Value = Evaluate(Replace("If(" & .Offset(, -2).Address & "=""Planned Downtime"",@&""-P"",@)", "@", .Address))
   End With
End Sub
 
Upvote 0
Try this which doesn't consider the full range. Use Fluf's for the full range per your request.

Code:
Sub Tsar()
If ActiveSheet.Range("B5") = "Planned Downtime" Then
ActiveSheet.Range("D5") = ActiveSheet.Range("D5") & "-P"
End If
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,172
Members
449,071
Latest member
cdnMech

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