VBA Using IF THEN within a textbox - Spreadsheet (not user form)

TBRoberts

New Member
Joined
Mar 11, 2016
Messages
23
I am most likely going about this all wrong but here goes nothing...

I am trying to pass a dynamic value into a textbox.

My textbox reads something like this:


Case(s) A, B, C, D generated given scenario(s) 1, 2, 3. There was/were X ProductType1 and Y ProductType2 totaling $$$$


I have my code as follows:

Dim CaseNum, Scen, NumProductType1, NameProductType1, NumProductType2, NameProductType2, Product1Total, Product2Total as string


Code:
    ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 39, 129.75, 503.25 _
        , 182.25).Select


        Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text _
    = "Case(s) " & CaseNum & " generated via the " & Scen & " scenario(s). " & "There were/was " & NumProductType1 _
    & NameProductType1 & "and " & NumProductType2 & NameProductType2 & "Totaling " & Format (Product1total, "currency") _
 & Format (Product2total, "currency") & "respectively."


I would like to pass into the text an IF statement that would allow the text to read more smoothly. For example, When there is only one case, scenario, or product type passed into the text, I would like it to get rid of the "(s)" and just make the text singular, and just keep one product type. For example, if there was only one case, scenario and product the text would read: "Case xxx alerted via the yyy scenario. There was one zzzz totaling $$$. Is there a way to pass an IF Then statement into a textbox???

Hope this makes sense. As always, thank you for your help!!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,597
Messages
6,125,741
Members
449,256
Latest member
Gavlaar

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