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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,318
Office Version
  1. 365
Platform
  1. Windows
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?
 

rc39452

Board Regular
Joined
Nov 9, 2004
Messages
77
I will try it now.....

No, i don't have to use VB. I can use conditional formating do you have any suggestions?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,318
Office Version
  1. 365
Platform
  1. Windows
Well you would need to use a formula.

Is it all entries beginning HQARM or is it only the ones mentioned in your post?
 

rc39452

Board Regular
Joined
Nov 9, 2004
Messages
77

ADVERTISEMENT

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?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,318
Office Version
  1. 365
Platform
  1. Windows
Well for the conditional formatting you would use the Formula is option with a formula like this:

=LEFT(A1,5)="HQARM"
 

rc39452

Board Regular
Joined
Nov 9, 2004
Messages
77

ADVERTISEMENT

how do you make the background turn colors.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,318
Office Version
  1. 365
Platform
  1. Windows
Goto Format... on the Conditional Formaatting form and select the Patterns tab.

You can set your colour/pattern there.
 

Forum statistics

Threads
1,147,844
Messages
5,743,511
Members
423,800
Latest member
IuneKeiki

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
Top