I need a macro that will insert an equals formula into a group of selected cells.
I have a macro (shown below) that finds a unique font color within my current selection. I need to add a function to the end of this macro. After the font color is found and those cells are then selected, I need a dialog box to pop up and ask “Select a Cell that These Cells Should Equal”, after that cell is selected, I need an equals formula (equaling that cell) inserted into the cells that have this font color.
I hope this makes sense. If not, please let me know if I need to give more information. Thank you in advance.
I have a macro (shown below) that finds a unique font color within my current selection. I need to add a function to the end of this macro. After the font color is found and those cells are then selected, I need a dialog box to pop up and ask “Select a Cell that These Cells Should Equal”, after that cell is selected, I need an equals formula (equaling that cell) inserted into the cells that have this font color.
I hope this makes sense. If not, please let me know if I need to give more information. Thank you in advance.
Code:
Sub Macro4()'
' Macro4 Macro
'
'
Dim rngFound As Range, rngAll As Range
Dim strFirst As String, lColor As Variant, arrColors As Variant
arrColors = Array(RGB(194, 5, 5))
With Selection
For Each lColor In arrColors
With Application.FindFormat
.Clear
.Font.Color = lColor 'Search for font color
End With
On Error Resume Next
Set rngFound = .Find("", .Cells(.Cells.Count), SearchFormat:=True)
On Error GoTo 0
If Not rngFound Is Nothing Then
strFirst = rngFound.Address
Do
If rngAll Is Nothing Then
Set rngAll = rngFound
Else
Set rngAll = Union(rngAll, rngFound)
End If
Set rngFound = .Find("", rngFound, SearchFormat:=True)
Loop While rngFound.Address <> strFirst
End If
Next lColor
End With
If Not rngAll Is Nothing Then
rngAll.Select
Set rngAll = Nothing
Set rngFound = Nothing
strFirst = vbNullString
Else
MsgBox "No cells found with any font color "
End If
Application.FindFormat.Clear
End Sub