NoviceLois
New Member
- Joined
- Nov 22, 2019
- Messages
- 12
- Office Version
- 2016
- Platform
- Windows
I am new to VBA and programming in general. I am trying to right align all the values in cells, unless they contain "R", then I want the "R" center aligned, bolded and in red. On each worksheet in the workbook. Thru the generosity of others I was able to find code to eliminate worksheets I do not want changed, and to right align. I used a macro to get the code for conditional formatting to make the "R" bolded Red. But to center align just the cells with the "R" has yielded nothing but compile errors. Thank you in advance for your kind assistance.
Here is the code so far.
Here is the code so far.
Code:
Option Explicit
Sub rgtalgnredRctr()
Dim rs As Worksheet
Dim Cell As Range
For Each rs In ThisWorkbook.Worksheets
If rs.Name <> "Data" And rs.Name <> "Tools" Then
Range("E4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
With Selection '
' Rightjustify Macro
'
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End If
Range("E2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""R"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Color = -16777024
.TintAndShade = 0
End With
Range("E2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
For Each Cell In Selection
If Cell.Value = "R" Then
Cell.HorizontalAlignment = xlCenter
End If
Next Cell
End Sub
Last edited by a moderator: