VBA needs to add ".0" (as 1.0)

sksanjeev786

Well-known Member
Joined
Aug 5, 2020
Messages
961
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Team,

I have been using the below macro recently which change the color as per my requirement and everything works perfectly but i need to add .0 if we have a single decimal column C,D,E and G with yellow highlighted.

Can anyone help me with this?

VBA Code:
Sub ColourNumbers()
Dim Lrow As Long, Lcol As Long
Dim rng As Range

With Sheets("Sheet1") 'change to your sheet name or use With ActiveSheet
    Lrow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Lcol = .Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
End With
For Each rng In Range(Cells(1, 2), Cells(Lrow, Lcol))
    If Trim(InStr(rng, " ")) = 0 Then
        rng.Font.Color = vbBlack
    Else
        rng.Characters(1, InStr(rng, " ")).Font.Color = vbBlack
    End If
Next

End Sub



Book1
ABCDEFG
1Unaided Brand Awareness (First Mention)27-0.9-6.0 q0.4271.5
2Unaided Brand Awareness (Any Mention)470.8-6.5 q-0.247-0.2
3Aided Brand Awareness853.6 r3.9 r1851.5
4Message Association17-2.8-3.90.7170.5
5Book Intent - Business290.21.2-0.9293
6Book Intent - Personal/Leisure5900.30.9590.1
7Leisure Travel Consideration603.23.3260-0.2
8Business Travel Consideration9-2.5-1-2.59-4.3 q
9Affinity533.6-1.5-3.853-1.4
10Unique323.9-0.5-3.9326.0 p
11Meets Needs52-1.80.1-0.552-0.7
Sheet1
 
Last edited by a moderator:
First you paste in the code, then you select what you just pasted, then you click the VBA button in the edit toolbar to apply code tags.
That is one way. I find it easier to insert the code tags first so this appears
[CODE=vba][/CODE]
and then just paste my code between those two tags, saves selecting the code again after pasting it.
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi Bebo,

once again thank you so much for your help on this.

just wanted to check can we add "+" symbole (+0.8, +3.6 and for 0.0 it will be as 0.0 ) only and "-" data stay same..

Regards
Sanjeev
Could you put full representative samples into mini sheet then upload again?
 
Upvote 0
Could you put full representative samples into mini sheet then upload again?
Hi Bebo,

For now i have only added in column "C"

Book4
ABCDEFG
1Unaided Brand Awareness (First Mention)27-0.9-6.0 q0.4271.5
2Unaided Brand Awareness (Any Mention)47+0.8-6.5 q-0.247-0.2
3Aided Brand Awareness85+3.6 r3.9 r1851.5
4Message Association17-2.8-3.90.7170.5
5Book Intent - Business29+0.21.2-0.9293
6Book Intent - Personal/Leisure590.00.30.9590.1
7Leisure Travel Consideration60+3.23.3260-0.2
8Business Travel Consideration9-2.5-1-2.59-4.3 q
9Affinity53+3.6-1.5-3.853-1.4
10Unique32+3.9-0.5-3.9326.0 p
11Meets Needs52-1.80.1-0.552-0.7
Sheet1
 
Upvote 0
The code still works for me. See before and after screenshot

Capture.JPG
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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