sksanjeev786
Well-known Member
- Joined
- Aug 5, 2020
- Messages
- 996
- Office Version
- 365
- 2016
- Platform
- Windows
Hi Team,
I have a macro which applies color on each cell but while changing the color I don't want "Ctrl" data font size increase I want same as per template
and data are in same cell i.e 2.9 and Ctrl 67% are in same cell...
can anyone help me to get the macro as per image 1 where ctrl data font size remain same and greay data font also remain same as per image 1
First image i did manully and 2nd image with Macro..
,
I have a macro which applies color on each cell but while changing the color I don't want "Ctrl" data font size increase I want same as per template
and data are in same cell i.e 2.9 and Ctrl 67% are in same cell...
can anyone help me to get the macro as per image 1 where ctrl data font size remain same and greay data font also remain same as per image 1
First image i did manully and 2nd image with Macro..
VBA Code:
Public Sub HighlightBoldWhitenAndRemoveLetters()
Dim ActiveShape As Shape
Dim shp As Shape
Dim objTable As Table
Dim targetColumn As Long
Dim targetRow As Long
Select Case Application.ActiveWindow.Selection.Type
Case ppSelectionShapes, ppSelectionText
For Each shp In Application.ActiveWindow.Selection.ShapeRange
Set ActiveShape = shp
Exit For
Next shp
Case Else
MsgBox "There is no shape currently selected!", vbExclamation, "No Shape Found"
Exit Sub
End Select
If ActiveShape.HasTable Then
Set objTable = ActiveShape.Table
targetColumn = 2
targetRow = 4
For targetRow = 4 To objTable.Rows.Count - 1
For targetColumn = 2 To objTable.Columns.Count
Dim cell As cell
Set cell = objTable.cell(targetRow, targetColumn)
With cell.Shape.TextFrame.TextRange
Dim cellText As String
cellText = .text
Dim checkText As String
If InStr(1, cellText, "Ctrl") > 0 Then
checkText = Left(cellText, InStr(1, cellText, "Ctrl") - 1)
Else
checkText = cellText
End If
If InStr(1, LCase(checkText), "p") > 0 Then
cell.Shape.Fill.ForeColor.RGB = RGB(79, 138, 16)
.Font.Bold = msoTrue
.Font.Color.RGB = RGB(255, 255, 255) ' White font color
.text = Replace(cellText, "p", "")
ElseIf InStr(1, LCase(checkText), "r") > 0 Then
cell.Shape.Fill.ForeColor.RGB = RGB(255, 150, 0)
.Font.Bold = msoTrue
.Font.Color.RGB = RGB(255, 255, 255) ' White font color
.text = Replace(cellText, "r", "")
ElseIf InStr(1, LCase(checkText), "q") > 0 Then
cell.Shape.Fill.ForeColor.RGB = RGB(204, 51, 51)
.Font.Bold = msoTrue
.Font.Color.RGB = RGB(255, 255, 255) ' White font color
.text = Replace(cellText, "q", "")
Else
cell.Shape.Fill.Visible = msoFalse
.Font.Bold = msoFalse
.Font.Color.RGB = RGB(0, 0, 0) ' Black font color
End If
End With
Next targetColumn
Next targetRow
Else
MsgBox "The selected shape is not a table!", vbExclamation, "Table Not Found"
End If
End Sub