Color background detection in a cell

Hippo8

New Member
Joined
Jan 7, 2013
Messages
4
Hi everyone, i'm facing some problems and i would like to ask for your help.

I have two columns with dates, where some of the dates are different.
Ex:

26-06-2009 16,07 26-06-2009
29-06-2009 16,22 29-06-2009
30-06-2009 16,09 30-06-2009
01-07-2009 16,24 01-07-2009
02-07-2009 16,04 02-07-2009
03-07-2009 16,03 06-07-2009
06-07-2009 16,04 07-07-2009
07-07-2009 16,01 08-07-2009
08-07-2009 15,92 09-07-2009

I need to search in all the file, for this situation an then copy the date in the left column to paste it in the right column. To stay like this:

26-06-2009 16,07 26-06-2009
29-06-2009 16,22 29-06-2009
30-06-2009 16,09 30-06-2009
01-07-2009 16,24 01-07-2009
02-07-2009 16,04 02-07-2009
03-07-2009 16,03 03-07-2009
06-07-2009 16,04 06-07-2009
07-07-2009 16,01 07-07-2009
08-07-2009 15,92 08-07-2009

With the conditional formatting i made all the different dates appear in red, which make the task more easy.

I'm now trying to automate the process with some vba. I'm trying to run the column A searching for a red background and then copy the date and insert as a new line in the other column.

Hope i express my self correctly.

If Range("A2:A1500").Interior.ColorIndex = -4142 Then

End If

I was trying some like this, there are a way so i know what the red background cell column and row are?

Then my objective is work with this recorded macro:
Rich (BB code):
Range("C360:D360").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A360").Select
Selection.Copy
Range("C360").Select
ActiveSheet.Paste
Range("D359").Select
Application.CutCopyMode = False
Selection.Copy
Range("D360").Select
ActiveSheet.Paste
Adapting the column number automatically.

Thank You

[mod note: crossposted here.]
 
Last edited by a moderator:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Does this help?

Code:
Sub Hippo8()

Dim rcell As Range
Dim lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row

For Each rcell In Range("A2:A" & lr)

    If rcell.Font.ColorIndex = 3 Then
    
        rcell.Offset(, 2).Value = rcell.Value
        
    End If
    
Next rcell

End Sub
 
Upvote 0
Does this help?

Code:
Sub Hippo8()

Dim rcell As Range
Dim lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row

For Each rcell In Range("A2:A" & lr)

    If rcell.Font.ColorIndex = 3 Then
    
        rcell.Offset(, 2).Value = rcell.Value
        
    End If
    
Next rcell

End Sub


Hi John,

Thank you very much for your help.

Sub Subst()
Dim rcell As Range
Dim lr As Long


lr = Cells(Rows.Count, 1).End(xlUp).Row
For Each rcell In Range("A2:A" & lr)
'MsgBox (rcell.Font.ColorIndex)
If rcell.Font.ColorIndex = 3 Then
rcell.Offset(, 4).Value = rcell.Value
'MsgBox (rcell)

Range(rcell.Offset(, 4)).Select
'Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End If

Next rcell
End Sub

I'm having a problem making the selection. You know how can i select this 'cell':
rcell.Offset(, 4).Value = rcell.Value

I think that if i can select it, i'll then insert a new line and then make the rcell.

Thank You
 
Upvote 0
Maybe:

rcell.Offset(,4).Select

Not sure about what you are trying to achieve. Are you copying a value to an adjacent cell or inserting? Or do you want the formating copied to the adjacent cell (ie. Column C or is it Column D)
 
Upvote 0
Hippo8 I think you need to read the post made by Kenneth Hobs in your cross-post.
 
Upvote 0
Maybe:

rcell.Offset(,4).Select

Not sure about what you are trying to achieve. Are you copying a value to an adjacent cell or inserting? Or do you want the formating copied to the adjacent cell (ie. Column C or is it Column D)

I'm copying a value from one cell to another, which your code really helped.

datexdatey
17a17a
18b18b
21c22c
22d23d

<tbody>
</tbody>


With this code:
Sub MINHA()
Dim rcell As Range
Dim lr As Long


lr = Cells(Rows.Count, 1).End(xlUp).Row
For Each rcell In Range("A2:A" & lr)
'MsgBox (rcell.Font.ColorIndex)
If rcell.Font.ColorIndex = 3 Then
rcell.Offset(, 2).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
rcell.Offset(, 3).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
rcell.Offset(, 2).Value = rcell.Value
End If

Next rcell
End Sub

I create a new row and insert the red date. Stay like that:


datexdatey
17a17a
18b18b
21c21
22d22d

<tbody>
</tbody>



What i want to do now is insert the last value in the Y column. Ex:


datexdatey
17a17a
18b18b
21c21b
22d22d

<tbody>
</tbody>

Could you help me doing that?

Really appreciate.

Thank You
 
Upvote 0
Seeing as you are obviously not using conditional formatting...

Code:
rcell.Offset(, 3).Value = rcell.Offset(-1, 3).Value
 
Upvote 0

Forum statistics

Threads
1,215,842
Messages
6,127,235
Members
449,372
Latest member
charlottedv

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