98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Range.text in and If statement
Range.text in and If statement
Resolved · Low Priority · Version 2010
Simran has attended:
Excel Advanced course
Excel VBA Introduction course
Excel VBA Intermediate course
Range.text in and If statement
Hi,
I'm wondering if you can please help with a specific macro I am trying to create.
I'm trying to fill some cells in a dashboard with text and colour, once certain criteria are met.
The colour fill works absolutely fine, but when I added the "and text" string (£, ££ or £££) it doesn't work.
Can you please tell me where I'm going wrong?
Many thanks,
Simran
Sub ApplicationCost()
Dim SumOMS As Long
Dim SumEMS As Long
SumOMS = Application.SumIf(Range("B:G"), "Order Management", Range("G:G"))
SumEMS = Application.SumIf(Range("B:G"), "EMS", Range("G:G"))
If SumOMS > 5000000 Then
Range("K7").Interior.Color = vbRed And Range("K7").Text = "$$$"
ElseIf SumOMS > 2500000 Then
Range("K7").Interior.Color = vbYellow And Range("K7").Text = "$$"
Else:
Range("K7").Interior.Color = vbGreen And Range("K7").Text = "$"
End If
End Sub
RE: Range.text in and If statement
Hi Simran,
Thanks for your question. If you simply want to have £, ££ or £££ in the cell, you could try for example:
Range("K7").Interior.Color = vbRed
Range("K7").Value = "£"
without using "and" in your code
If you want to show the result of the Sumif formatted with £ symbols, you could try:
Range("K7").Interior.Color = vbRed
Range("K7") = format(SumOMS,"£#,##0.00")
which shows the result as a currency. You can use more than one £ symbol here.
I hope this helps.
Kind regards
Marius Barnard
Excel Trainer
RE: Range.text in and If statement
That works perfectly thank you very much!
RE: Range.text in and If statement
Hi Simran,
You're most welcome.
Kind regards
Marius
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Create Charts with One keystrokeCreate a graph with one click |