copy contents from cell if condional format is true into another cell

Kerry M

New Member
Joined
Oct 22, 2016
Messages
12
here goes ...

I am working on a Carpark problem we have at work

I go around all the parking spots and enter the Car Registration plates every hour,
If the same car is there 3Hours I use conditional formatting to highlight cell as BLUE eg. A to D = 3 Hours
If the car is STAFF colour RED

1ABCDEFGHI
26:007:008:009:0010:00
3STAFF<-- RED
=D3
4REGO1REGO1REGO1REGO1
<-- BLUE
=D4

<tbody>
</tbody>


what i need to do is, when any cell on the row from B to I = colour RED or BLUE then copy contents to Column J with that colour
as it occurs
then the same for next row etc.etc

Any help would be Appreciated

P.S. Hope you get what i mean :)
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
With VBA :
Code:
Const ColRED As Integer = 3
Const ColBLUE As Integer = 42

Sub lol()

Dim Valid As Boolean
Dim L As Integer, C As Integer
Dim i As Integer

Valid = False 'Valid=True if we have an empty row -> we end
L = 2 'Starting row

While Valid = False
    i = 0
    For C = 2 To 9 'from column B to I
        If Cells(L, C).Interior.ColorIndex = ColRED Then 'if it's red
            Cells(L, 10) = Cells(L, C) 'we copy the value
            Cells(L, 10).Interior.ColorIndex = ColRED 'we set the red color
            
        ElseIf Cells(L, C).Interior.ColorIndex = ColBLUE Then 'if it's blue
            If i = 3 Then '3Hours
                Cells(L, 10) = Cells(L, C) 'we copy the value
                Cells(L, 10).Interior.ColorIndex = ColBLUE 'we set the blue color
            End If
            
        Else
            i = i + 1 'if i=8 then we have an empty row so we leave
        End If
        
        If i = 8 Then 'empty row
            Valid = True
        End If
        
    Next C
    
    L = L + 1 'next row
Wend

End Sub

You have to make sure the 2 constants are good so it works fine.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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