How do I change the font color in a range of cells to the same font color in another range of cells using a vba.

Patches01

New Member
Joined
Aug 11, 2021
Messages
21
Office Version
  1. 365
Platform
  1. Windows
I want to change the font color in a range of cells to the same font color in another range of cells using a vba.

I have the below code however it only seems to work with one cell to another cell not a range of cells.


Me.Range("g4").Font.ColorIndex = Me.Range("f4").Font.ColorIndex

Thank you
 
I apologise. I a new to VBN coding. To be more clear.
I have a sheet that is used for balancing deposits paid and refunded the following information is used.
Date, Name, Money paid or refunded and the initials of the staff member entering the information.
For Example
A4 = DATE, B4 = NAME, C4, D4.E4 AND F4 = THE DOLLOR AMOUNT PAID OR REFUNDED, G4 = THE INITIALS OF THE STAFF MEMBER
When the dollar amount is entered I have a code for the amount to change font color to RED if it is a refund to a customer and to stay BLACK if it is a payment to the business.
I require A4, B4 and G4 to change RED when a REFUND occurs.
Here is the code as I have it so far.
Private Sub CommandButton2_Click()

Dim myRange As Range
Set myRange = Range("c4:f42")

For Each Cell In myRange
If Cell.Value < 0 Then Cell.Font.ColorIndex = 3


Set myRange = Range("c4:f42")


If Cell.Value > 0 Then Cell.Font.ColorIndex = 1


Next

Thank you for your help
Only one cell from C4, D4, E4 and F4 will have a number entered into it the other 3 cells will be empty
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Since you are already using code modify it like this:
VBA Code:
Private Sub CommandButton2_Click()
Dim myRange As Range, i as long
Set myRange = Range("c4:f42")

For Each Cell In myRange
i = cell.row
If Cell.Value < 0 Then
Cell.Font.ColorIndex = 3
range("A"& i).Font.ColorIndex = 3
range("B"& i).Font.ColorIndex = 3
range("G"& i).Font.ColorIndex = 3
elseIf Cell.Value > 0 Then
Cell.Font.ColorIndex = 1
range("A"& i).Font.ColorIndex = 1
range("B"& i).Font.ColorIndex = 1
range("G"& i).Font.ColorIndex = 1
end if
Next cell
...
 
Upvote 0
Solution
T
Since you are already using code modify it like this:
VBA Code:
[/QUOTE]
[QUOTE="bobsan42, post: 5735853, member: 153686"]
Private Sub CommandButton2_Click()
Dim myRange As Range, i as long
Set myRange = Range("c4:f42")

For Each Cell In myRange
i = cell.row
If Cell.Value < 0 Then
Cell.Font.ColorIndex = 3
range("A"& i).Font.ColorIndex = 3
range("B"& i).Font.ColorIndex = 3
range("G"& i).Font.ColorIndex = 3
elseIf Cell.Value > 0 Then
Cell.Font.ColorIndex = 1
range("A"& i).Font.ColorIndex = 1
range("B"& i).Font.ColorIndex = 1
range("G"& i).Font.ColorIndex = 1
end if
Next cell

[/QUOTE]

Since you are already using code modify it like this:
VBA Code:
Private Sub CommandButton2_Click()
Dim myRange As Range, i as long
Set myRange = Range("c4:f42")

For Each Cell In myRange
i = cell.row
If Cell.Value < 0 Then
Cell.Font.ColorIndex = 3
range("A"& i).Font.ColorIndex = 3
range("B"& i).Font.ColorIndex = 3
range("G"& i).Font.ColorIndex = 3
elseIf Cell.Value > 0 Then
Cell.Font.ColorIndex = 1
range("A"& i).Font.ColorIndex = 1
range("B"& i).Font.ColorIndex = 1
range("G"& i).Font.ColorIndex = 1
end if
Next cell
...
Thank you so much it works.
You're a legend.
Since you are already using code modify it like this:
VBA Code:
Private Sub CommandButton2_Click()
Dim myRange As Range, i as long
Set myRange = Range("c4:f42")

For Each Cell In myRange
i = cell.row
If Cell.Value < 0 Then
Cell.Font.ColorIndex = 3
range("A"& i).Font.ColorIndex = 3
range("B"& i).Font.ColorIndex = 3
range("G"& i).Font.ColorIndex = 3
elseIf Cell.Value > 0 Then
Cell.Font.ColorIndex = 1
range("A"& i).Font.ColorIndex = 1
range("B"& i).Font.ColorIndex = 1
range("G"& i).Font.ColorIndex = 1
end if
Next cell
...
Thank you so much. It works.
You're a legend.
 
Upvote 0

Forum statistics

Threads
1,214,853
Messages
6,121,935
Members
449,056
Latest member
denissimo

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