VBA Help!

steveo0707

Board Regular
Joined
Mar 4, 2013
Messages
85
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
The following is the code I have written for my worksheet. I am getting the program to do everything except for the last Case Parameters. It's not putting the © in the F column nor shading the cell green. I have also already tried making it an If statement and that did not work either.

VBA Code:
Sub Scanning()
    Dim YELLOW As Variant
    Dim OFF_GREEN As Variant
    Dim GREEN As Variant
    Dim Row As Long
    ' DEFINE THE COLORS
    YELLOW = RGB(255, 255, 91)
    OFF_GREEN = RGB(196, 215, 155)
    GREEN = RGB(54, 248, 54)
    ' CYCLE THROUGH ROWS
    Row = 1 
          
    Do Until Range("E" & Row).Value = VBA.Constants.vbNullString
        ' CHECKING COLUMN E
        Select Case Range("E" & Row).Value
            Case "Working On"
                Range("A" & Row).Interior.Color = YELLOW
            Case "In Box"
                Range("A" & Row & ":B" & Row).Interior.Color = YELLOW
            Case "Crate Built"
                Range("F" & Row).Value = "©"
                Range("F" & Row).Interior.Color = GREEN
                
         End Select
        
               ' IF YOU ARE LOOKING FOR JUST A LETTER D IN COLUMN F
        If Range("F" & Row).Value = "D" Then Range("C" & Row).Interior.Color = OFF_GREEN
               
        Row = Row + 1
    Loop
End Sub
 
If you step through the code, how many times does it go through the loop?
Having had another look at your image, I suspect it's only going through once.
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Ok how about
VBA Code:
Sub Scanning()
   Dim YELLOW As Variant
   Dim OFF_GREEN As Variant
   Dim GREEN As Variant
   Dim Cl As Range
   
   ' DEFINE THE COLORS
   YELLOW = RGB(255, 255, 91)
   OFF_GREEN = RGB(196, 215, 155)
   GREEN = RGB(54, 248, 54)
   ' CYCLE THROUGH ROWS
   
   For Each Cl In Range("E2", Range("E" & Rows.Count).End(xlUp))
   ' CHECKING COLUMN E
      Select Case Cl.Value
         Case "Working On"
            Cl.Offset(, -4).Interior.Color = YELLOW
         Case "In Box"
            Cl.Offset(, -4).Resize(, 2).Interior.Color = YELLOW
         Case "Crate Built"
            Cl.Offset(, 1).Value = "©"
            Cl.Offset(, 1).Interior.Color = GREEN
      End Select
      
      ' IF YOU ARE LOOKING FOR JUST A LETTER D IN COLUMN F
      If Cl.Offset(, 1).Value = "D" Then Cl.Offset(, -2).Interior.Color = OFF_GREEN
      
   Next Cl
End Sub
 
Upvote 0
One last question. Once I have shipped this item, I need cells to go back to having no highlights. How would I incorporate that into the code?
 
Upvote 0
Maybe
VBA Code:
   For Each Cl In Range("E2", Range("E" & Rows.Count).End(xlUp))
   ' CHECKING COLUMN E
      Select Case Cl.Value
         Case "Working On"
            Cl.Offset(, -4).Interior.Color = YELLOW
         Case "In Box"
            Cl.Offset(, -4).Resize(, 2).Interior.Color = YELLOW
         Case "Crate Built"
            Cl.Offset(, 1).Value = "©"
            Cl.Offset(, 1).Interior.Color = GREEN
         Case Else
            Cl.Offset(, -4).Resize(, 2).Interior.Color = xlNone
            Cl.Offset(, 1).Interior.Color = xlNone
      End Select
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,889
Messages
6,122,097
Members
449,065
Latest member
albertocarrillom

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