VB simple code help

rc39452

Board Regular
Joined
Nov 9, 2004
Messages
77
Can someone help me with this? I'm got this information from another post and trying to use it. I need to color all of the entries that begin with "HQARM 3" "HQARM 4" "HQARM 8" "HQARM 9" any suggestion will be greatly appreciated.

If Left(ActiveCell, 7) = "HQARM 3" Then
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid

If Left(ActiveCell, 7) = "HQARM 4" Then
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid

If Left(ActiveCell, 7) = "HQARM 8" Then
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid

If Left(ActiveCell, 7) = "HQARM 9" Then
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
What problem are you actually having?

Does this work?
Code:
Dim strTest
Dim c As Range

    Set c = ActiveCell
    strTest = Left(c, 7)
    Select Case strTest
        Case "HQARM 3", "HQARM 4", "HQARM 8", "HQARM 9"
        
            With c.Interior
            .ColorIndex = 6
            .Pattern = xlSolid
            End With
        Case Else
            ' do nothing
    End Select

BTW do you really need to use VBA, can't you use Conditional formatting?
 
Upvote 0
I will try it now.....

No, i don't have to use VB. I can use conditional formating do you have any suggestions?
 
Upvote 0
Well you would need to use a formula.

Is it all entries beginning HQARM or is it only the ones mentioned in your post?
 
Upvote 0
that didn't seem to work. I'm copying and pasting it into existing code.
I probably have to send you the entire code for you to make the ajustments.

I think the conditional formatting may be better?
 
Upvote 0
Well for the conditional formatting you would use the Formula is option with a formula like this:

=LEFT(A1,5)="HQARM"
 
Upvote 0
Goto Format... on the Conditional Formaatting form and select the Patterns tab.

You can set your colour/pattern there.
 
Upvote 0

Forum statistics

Threads
1,218,625
Messages
6,143,574
Members
450,493
Latest member
Woejeber

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