Select cells based on colour, copy and paste as values

stuartnoble54

New Member
Joined
Feb 3, 2017
Messages
1
Hi Everyone,

I am creating P&L's that pull out numbers on OLE functions from my finance system. The end users of the P&L's do not have the permissions for this and values must be copied and pasted to hard code them.

I am looking for some code that will select multiple ranges of OLE cells, copy and paste as values.

I have been trying to do this by colouring the cells light grey (2) and picking them based on cell colour and found the following code to help identify this. I'm struggling to change this so it will copy and paste rather than display the ranges to me in a pop up - in honesty I don't understand it.
Sub YRange()
Dim c As Range, Yc As Range
For Each c In Range("A15:Z15")
If c.Interior.ColorIndex = 6 Then
If Yc Is Nothing Then
Set Yc = c
Else
Set Yc = Union(Yc, c)
End If
End If
Next c
If Not Yc Is Nothing Then MsgBox Yc.Address(False, False)
End Sub
Any suggestions welcome :)

Thanks in advance
Stuart
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
- in honesty I don't understand it.
Sub YRange()
Dim c As Range, Yc As Range
For Each c In Range("A15:Z15")
If c.Interior.ColorIndex = 6 Then
If Yc Is Nothing Then
Set Yc = c
Else
Set Yc = Union(Yc, c)
End If
End If
Next c
If Not Yc Is Nothing Then MsgBox Yc.Address(False, False)
End Sub
Any suggestions welcome :)

Thanks in advance
Stuart

Stuart,
Welcome to the forum.
The code you provided does exactly what you described. The 'c' is a variable to identify each cell address being evaluated using the fill color ' c.Interior.ColorIndex = 6' to determine if the cell address should be accumulated in the ' Union(Yc, c)'. The macro checks ' Each c In Range("A15:Z15")' , ie.each cell in the range.

So something like the following should copy each cell with the ' c.Interior.ColorIndex = 6' to the corresponding cell on "yoursheetname". Don't forget to use the double quotes on each end of 'yoursheetname'. Change 'yoursheetname' to the name of the sheet where you will be copying the greyed cells to, ie. "Sheet2", or "mySheet", or whatever. I hope this is helpful.
Perpa

Code:
Sub CpyToNewSheet()
 Dim c As Range   ', Yc As Range
     For Each c In Range("A15:Z15")     'Just one row???
         If c.Interior.ColorIndex = 6 Then
             Sheets("yoursheetname").range(c).value = c.value
         End If
     Next c
Sheets("yoursheetname").activate
 
 End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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