Results 1 to 2 of 2
2015-08-11, 19:20 #1
- Join Date
- Sep 2014
- Thanked 0 Times in 0 Posts
How to align Bold words to the left or right
I'm trying to do 2 things. I'm working with MS Excel 2013 with a sheet named "Proposal".
1. What I would like to do is in Cell A30 thru A162 if a word shows up as bold I need it to align to the left. This cell is pulling information from "=Sheet1!A9 thru =Sheet1!A141" Some of the cells will show numbers, which I would like to align to the center.
2. Starting on Line 30 thru 162 I have merge BCD as one cell. In this location if a word shows up Bold I need to align it to the right. This cell is pulling information from "=Sheet1!B9 thru =Sheet1!141.
I appreciate any help that I can get on this.
2015-08-11, 20:10 #2
- Join Date
- Aug 2010
- Pa, USA
- Thanked 621 Times in 566 Posts
Here is some code that will do what I hope you wanted.
Col A rows 30 to 162
1. If bolded text = align Left
2. Not bolded text = align right
3. Bolded numbers = align center
4. Non bolded numbers = align right
col B rows 30 to 162
1. Anything bold = align right
2. Anything Not bolded = align left
Assumed that not bolded text and numbers in column should align right since you didn't specify
In a standard module:
Public Sub CkBold() Dim rng As Range, cell As Range Set rng = ActiveSheet.Range("A30:A162") For Each cell In rng If cell.Font.Bold = True Then If WorksheetFunction.IsNumber(cell) Then cell.HorizontalAlignment = xlCenter Else: cell.HorizontalAlignment = xlLeft End If Else: cell.HorizontalAlignment = xlRight End If If Range(cell.Offset(0, 1), cell.Offset(0, 3)).Font.Bold = True Then Range(cell.Offset(0, 1), cell.Offset(0, 3)).HorizontalAlignment = xlRight Else: Range(cell.Offset(0, 1), cell.Offset(0, 3)) = xlLeft End If Next cell End Sub