Return text with text colour

Closed
TheQ1991 Posts 2 Registration date Saturday 10 June 2017 Status Member Last seen 10 June 2017 - 10 Jun 2017 à 10:22
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 12 Jun 2017 à 11:48
Hi

Is there a way of doing the following for example?

In cell B1 for example, I would like whatever is in A1, but with the same text colour.

So if A1 is 'hello' in red, then B1 the will return 'hellos' in red

Thanks
Related:

3 responses

Mazzaropi Posts 1983 Registration date Monday 16 August 2010 Status Contributor Last seen 24 May 2023 147
10 Jun 2017 à 12:34
TheQ1991, Good afternoon.

I believe you need to use a VBA Excel programation to do what you want.
TheQ1991 Posts 2 Registration date Saturday 10 June 2017 Status Member Last seen 10 June 2017
10 Jun 2017 à 20:48
Thank you.

Any idea what the VBA code would be?
vcoolio Posts 1411 Registration date Thursday 24 July 2014 Status Contributor Last seen 6 September 2024 262
10 Jun 2017 à 21:16
Hello TheQ1991,

Try the following Worksheet_Change event code placed in the sheet module:-


Private Sub Worksheet_Change(ByVal Target As Range)


If Target.Count > 1 Then Exit Sub
If Target.Value = vbNullString Then Exit Sub
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub

        If Target.Value <> "" And Target.Font.ColorIndex = 3 Then
        Target.Offset(, 1).Value = Target.Value
        Target.Offset(, 1).Font.ColorIndex = 3
End If

End Sub


With the above code, if any cell in Column A is not empty and is formatted to red font, then the value in the adjacent cell in Column B will equal the value in the cell in Column A and in red font. Otherwise, nothing will happen.

To implement the code, right click on the sheet tab, select "view code" from the menu that appears and in the big white field that then appears, paste the above code.

I hope that this helps.

Cheerio,
vcoolio.

P.S. To execute the code:
Once you enter a value in any cell in Column A and then click away (or press enter or down arrow), the code will execute.
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 555
12 Jun 2017 à 11:48
Hi TheQ1991,

Or a more general approach then vcoolio's code:

Sub RunMe()
For Each cell In Range("A:A")
    If cell.Value <> vbNullString Then
        cell.Copy cell.Offset(0, 1)
    End If
Next cell
End Sub


Whenever there is a value in column A, copy it to the adjacent with all formats applied.

This code needs to be placed in a standard module and run manually, if you choose to use it.

Best regards,
Trowa