Colouring cells based on contains value

CawstonT

New Member
Joined
Feb 2, 2024
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm struggling to figure out how to colour cells based on a string in the cell
my excel data looks like this
I will have problems with the 0s and planned on dealing with it later or removing it from the data output source
Name
1.01 - words
1.02 - words
1.03 - words
1.04 - words
and sometimes like this
1-1 - words
1-2 - words
1-3 - words
1-4 - words

VBA Code:
Sub ColourHeaders()
'
' ColourHeader Macro
'
' Keyboard Shortcut: Ctrl+k
'
    Dim sReturn As String
    sReturn = InputBox("Enter Item section number ex.1 for section with numbers of 1-1,1-2... : ")
    Dim sReturn1 As String
    sReturn1 = InputBox("Specify . or - for deliniation")
    Dim sReturn2 As String
    sReturn2 = InputBox("0 before singles numbers ex. 01 enter yes or no")
    Dim count As String
    Dim counter As Integer
    counter = ActiveCell.Row
    Dim counter2 As Integer
    counter2 = 1
    Dim x As Range
    Set x = Range(ActiveCell, ActiveCell.Offset(0, 0))
    Dim y As Range
    Set y = Range(ActiveCell, ActiveCell.Offset(0, 0))
    
    
Do While x.Offset(counter, 0).Value <> ""
    If sReturn2 <> "no" Then
    count = "0" & CStr(counter2)
    End If
    If sReturn2 <> "yes" Then
    count = CStr(counter2)
    End If
    If InStr(1, CStr(y.Offset(counter - 1, 0).Value), sReturn & sReturn1 & count) <> 0 Then
    y.Offset(counter - 1, 0).Resize(1, 11).Interior.Color = RGB(165, 165, 165)
    counter2 = counter2 + 1
    End If
    counter = counter + 1
Loop
MsgBox y.Offset(counter - 1, 0).Value
MsgBox count
MsgBox counter
MsgBox counter2
MsgBox sReturn & sReturn1 & count
End Sub

Thanks for the help
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Do some research into conditional formatting which will allow you to do what you want without a macro.
 
Upvote 0
Do some research into conditional formatting which will allow you to do what you want without a macro.
Yeah I was going to include this into a single macro that would add other formatting to my worksheets, however it is probably just as quick to make a conditional colouring format without as you mentioned
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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