Vba : Need help , extract contain 2 cell color/background

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi expert...

i have set data with contain 2 cell color, blue and yellow..
i want to extract which only data/value with contain blue, can be extract

productafter vba
mango (cell color yellow)
papaya (cell color blue)
papaya
orange (no cell color)
banana (cell color blue)
banana

<tbody>
</tbody>

it's possible??

for somebody help me, i appreciated....

thank in advance...........
 

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
Code:
Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
scolor = 5 ' to be changed
For r = 2 To LR
'  c = Cells(r, 1).Interior.ColorIndex ' to see color
  If Cells(r, 1).Interior.ColorIndex = scolor Then Cells(r, 2).Value = Cells(r, 1).Value
Next
End Sub
 
Upvote 0
you have to know the number of blue color you are using and assign it to scolor, ther'is many blue.
To see color number uncomment the line
Code:
  c = Cells(r, 1).Interior.ColorIndex ' to see color
then run the code step by step with F8

if problems paste here a link to your file
 
Upvote 0
This forum does not allow attachments so we have to guess what you did not explain.

A range's interior color or colorindex can be used. They are not the same value. The more complicated scenario is if you used conditional formats for these interiors.

Place the code in a module and run it with that sheet active.

Code:
Sub a()
  Dim LR As Long, ciRed As Integer, ciYellow As Integer, r As Long, c As Range
  ciRed = 3
  ciYellow = 6
  LR = Cells(Rows.Count, "A").End(xlUp).Row
  For r = 2 To LR
    Set c = Cells(r, 1)
    Debug.Print r, c.Address, c.Interior.ColorIndex ' to see colorindex in Immediate Window
    If c.Interior.ColorIndex = ciRed Or c.Interior.ColorIndex = ciYellow Then Cells(r, 2).Value = Cells(r, 1).Value
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,314
Messages
6,124,202
Members
449,147
Latest member
sweetkt327

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