conditional format to change alignment in a cell if a number is entered

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
826
Office Version
  1. 365
Platform
  1. Windows
Hi
Column B is formatted to align left.
Sometimes i enter a number instead of a text.
I then click on a button on the ribbon to change the ailgnment
I got to wondering.......
Is there a way to have conditional format change it?

mike
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi
Column B is formatted to align left.
Sometimes i enter a number instead of a text.
I then click on a button on the ribbon to change the ailgnment
I got to wondering.......
Is there a way to have conditional format change it?

mike
Why do you have it left aligned if you want numbers aligned (presumably?) right. Why not let Excel do its default thing of numbers right & text left?

If I have understood incorrectly then please give more detail of exactly what you have and what you are trying to do.

If you allow vba then you could do it with a Worksheet_Change event code like below. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1.
3. Close the Visual Basic window & test.
4. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm).

Note that IsNumeric can sometimes interpret something as Numeric that you would not but see how this goes anyway if you are interested in the vba approach.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, cell As Range
  
  Set Changed = Intersect(Target, Columns("B"))
  If Not Changed Is Nothing Then
    For Each cell In Changed
      If IsNumeric(cell.Value) Then
        cell.HorizontalAlignment = xlRight
      Else
        cell.HorizontalAlignment = xlLeft
      End If
    Next cell
  End If
End Sub
 
Upvote 0
Why do you have it left aligned if you want numbers aligned (presumably?) right. Why not let Excel do its default thing of numbers right & text left?
Format the horizontal alignment as General
 
Last edited:
Upvote 0
Hi Peter_SSs
I made the column align left because most of the input is text.
once in a while, a number is entered.
By aligning it right, I can find it easier as I scroll up or down.
After your reply, I undid the column alignment and got the results i wanted
I never realized that excel did that with text and numbers
Even if i had thought of an event macro, I'd still need help writing it
I knew conditional format can change fonts and learned here that it can also change text, so I thought maybe alignment.
Your way was only one click

Thank you

mike :beerchug: :beerchug: have a couple, i'ts the weekend
 
Upvote 0
Hi footoo,
I saw your reply after I submitted the mine
Yep I think that's what i did by undoing the left aligning

Mike :beerchug::beerchug: :beerchug: Here's an extra one so you can catch up
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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