[vba]. read values in color only on vba.

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone.
How to read only the values with colors in a column and display this values in a row in another sheet, small example don't need xl2BB I think, so couple images can show my point.
this is what I have on sheet2
1596656309381.png

and this is the results I am expecting on sheet3
1596656341932.png

Please, Can anyone tell me how to do this.
thank you.
 

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
On sheet 2, in column L, are there several colors or is it just one color?
Is the color normal or is it highlighted with conditional formatting?
 
Upvote 0
If you have RGB try the following:

VBA Code:
Sub Macro7()
  With Sheets("Sheet2")
    .Range("L1", .Range("L" & Rows.Count).End(3)).AutoFilter 1, RGB(255, 192, 0), xlFilterCellColor
    .AutoFilter.Range.Offset(1).Copy
    Sheets("Sheet3").Range("B2").PasteSpecial xlPasteValues, , , True
    .ShowAllData
  End With
End Sub
 
Upvote 0
Here is another version because, well you just can never have too many programs. Be sure to copy and past this one in a Module


VBA Code:
Sub ColorMove()

Dim row1 As Integer
Dim col1 As Integer

Application.ScreenUpdating = False

col1 = 2
For row1 = 1 To 50

If Sheet2.Cells(row1, 12).Interior.ColorIndex > 1 Then

    Sheet2.Cells(row1, 12).Copy

    Sheet3.Cells(2, col1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
   
col1 = col1 + 1

End If

Next row1
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Sorry I just open this forum web. Thanks DanteAmor, what do you mean by [ " If you have RGB "] not all version has this. about the color, yes is normal, and I tried and do not work.
 
Upvote 0
Here is another version because, well you just can never have too many programs. Be sure to copy and past this one in a Module


VBA Code:
Sub ColorMove()

Dim row1 As Integer
Dim col1 As Integer

Application.ScreenUpdating = False

col1 = 2
For row1 = 1 To 50

If Sheet2.Cells(row1, 12).Interior.ColorIndex > 1 Then

    Sheet2.Cells(row1, 12).Copy

    Sheet3.Cells(2, col1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
  
col1 = col1 + 1

End If

Next row1
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub
Thank you Sir, is working
 
Upvote 0
Sorry about this, but I think I didn't mention is not just one column,
the columns to read are I, L, O, R, U, X, AA and for each one on sheet3 the display would be one after another
in case you don't mind, sorry.
 
Upvote 0
on sheet3 the display would be one after another
The next column of sheet2 in the next row of sheet3?

what do you mean by [ " If you have RGB "]
I mean the color of your cell.
Do you know the color number or RGB of your cell color?

Select a colored cell and run the following macro, it will show you in a message the RGB of the color of your cell.
VBA Code:
Sub getRGBcolor()
  Dim r, g, b, m
  With ActiveCell.Interior
    r = .Color Mod 256
    g = .Color \ 256 Mod 256
    b = .Color \ 65536 Mod 256
    MsgBox "R=" & r & " G=" & g & " B=" & b
  End With
End Sub
 
Upvote 0
Well this is a pretty big program but it should work. I hope I covered most of the criteria. If there is any other problems, let us know.

VBA Code:
Sub ColorMove()

Dim row1 As Integer
Dim row2 As Integer
Dim col1 As Integer
Dim col2 As Integer

Application.ScreenUpdating = False

Worksheets("Sheet3").Activate
Range("A1").CurrentRegion.Select
Selection.Delete Shift:=xlToLeft
With Sheet3
.Range("A2") = "I"
.Range("A3") = "L"
.Range("A4") = "O"
.Range("A5") = "R"
.Range("A6") = "U"
.Range("A7") = "X"
.Range("A8") = "AA"
End With

col1 = 2
row2 = 2

For row1 = 1 To 50
If Sheet2.Cells(row1, "I").Interior.ColorIndex > 1 Then
    Sheet2.Cells(row1, "I").Copy
    Sheet3.Cells(row2, col1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
col1 = col1 + 1
End If

Next row1

col1 = 2
row2 = 3
For row1 = 1 To 50
If Sheet2.Cells(row1, "L").Interior.ColorIndex > 1 Then
    Sheet2.Cells(row1, "L").Copy
    Sheet3.Cells(row2, col1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
col1 = col1 + 1
End If

Next row1

col1 = 2
row2 = 4
For row1 = 1 To 50
If Sheet2.Cells(row1, "O").Interior.ColorIndex > 1 Then
    Sheet2.Cells(row1, "O").Copy
    Sheet3.Cells(row2, col1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
col1 = col1 + 1

End If

Next row1

col1 = 2
row2 = 5
For row1 = 1 To 50
If Sheet2.Cells(row1, "R").Interior.ColorIndex > 1 Then
    Sheet2.Cells(row1, "R").Copy
    Sheet3.Cells(row2, col1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
col1 = col1 + 1

End If

Next row1

col1 = 2
row2 = 6

For row1 = 1 To 50
If Sheet2.Cells(row1, "U").Interior.ColorIndex > 1 Then
    Sheet2.Cells(row1, "U").Copy
    Sheet3.Cells(row2, col1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
col1 = col1 + 1

End If

Next row1

col1 = 2
row2 = 7

For row1 = 1 To 50
If Sheet2.Cells(row1, "X").Interior.ColorIndex > 1 Then
    Sheet2.Cells(row1, "X").Copy
    Sheet3.Cells(row2, col1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
col1 = col1 + 1

End If

Next row1

col1 = 2
row2 = 8

For row1 = 1 To 50
If Sheet2.Cells(row1, "AA").Interior.ColorIndex > 1 Then
    Sheet2.Cells(row1, "AA").Copy
    Sheet3.Cells(row2, col1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
col1 = col1 + 1
End If

Next row1

Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,646
Messages
6,125,997
Members
449,279
Latest member
Faraz5023

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