#1   Report Post  
Posted to microsoft.public.excel.programming
ED ED is offline
external usenet poster
 
Posts: 8
Default Alignment

Code please to align wording in a cell such as:

If cell E1 is greater than 0 the wording in cell is aligned right,
other wise wording in cell is aligned left.

Thanks in advance


Ed English

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Alignment

Since you're writing about wording, are you using e1 to control another cell?

If yes, how about something like:

Option Explicit
Sub testme01()

Dim myCell As Range
Dim myRng As Range

With ActiveSheet
Set myCell = .Range("e1")
Set myRng = .Range("f1")
End With

If myCell.Value 0 Then
myRng.HorizontalAlignment = xlRight
Else
myRng.HorizontalAlignment = xlLeft
End If

End Sub



ED wrote:

Code please to align wording in a cell such as:

If cell E1 is greater than 0 the wording in cell is aligned right,
other wise wording in cell is aligned left.

Thanks in advance

Ed English


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
ED ED is offline
external usenet poster
 
Posts: 8
Default Alignment

Thanks for the code..

I was not too clear in my original question, I'm working up a spread
sheet where I want the wording in column C cells to be aligned right
if there is a plus number value in the corresponding E cell, otherwise
the wording in column C is aligned left.

I thought that putting the following in C1:

=If(E10,myRng.HorizontalAlignment = xlRight,myRng.HorizontalAlignment
= xlLeft)


would set the alignment right in C1, then the the wording I put in C1
would be aligned right.

It doesn't seem to work. Any comments?




On Tue, 21 Jun 2005 13:21:17 -0500, Dave Peterson
wrote:

Since you're writing about wording, are you using e1 to control another cell?

If yes, how about something like:

Option Explicit
Sub testme01()

Dim myCell As Range
Dim myRng As Range

With ActiveSheet
Set myCell = .Range("e1")
Set myRng = .Range("f1")
End With

If myCell.Value 0 Then
myRng.HorizontalAlignment = xlRight
Else
myRng.HorizontalAlignment = xlLeft
End If

End Sub



ED wrote:

Code please to align wording in a cell such as:

If cell E1 is greater than 0 the wording in cell is aligned right,
other wise wording in cell is aligned left.

Thanks in advance

Ed English


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Alignment

To change the alignment, you're gonna need a macro. This doesn't go on the
worksheet itself.

This will adjust when you change something in column E.

Rightclick on the worksheet tab that should have this behavior. Select View
Code and paste this in the code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRng As Range
Dim myCell As Range

Set myRng = Intersect(Target, Me.Range("e:e"))

If myRng Is Nothing Then Exit Sub

On Error Resume Next
For Each myCell In myRng.Cells
If myCell.Value 0 Then
Me.Cells(myCell.Row, "C").HorizontalAlignment = xlRight
Else
Me.Cells(myCell.Row, "C").HorizontalAlignment = xlLeft
End If
Next myCell
On Error Goto 0

End Sub

ED wrote:

Thanks for the code..

I was not too clear in my original question, I'm working up a spread
sheet where I want the wording in column C cells to be aligned right
if there is a plus number value in the corresponding E cell, otherwise
the wording in column C is aligned left.

I thought that putting the following in C1:

=If(E10,myRng.HorizontalAlignment = xlRight,myRng.HorizontalAlignment
= xlLeft)

would set the alignment right in C1, then the the wording I put in C1
would be aligned right.

It doesn't seem to work. Any comments?

On Tue, 21 Jun 2005 13:21:17 -0500, Dave Peterson
wrote:

Since you're writing about wording, are you using e1 to control another cell?

If yes, how about something like:

Option Explicit
Sub testme01()

Dim myCell As Range
Dim myRng As Range

With ActiveSheet
Set myCell = .Range("e1")
Set myRng = .Range("f1")
End With

If myCell.Value 0 Then
myRng.HorizontalAlignment = xlRight
Else
myRng.HorizontalAlignment = xlLeft
End If

End Sub



ED wrote:

Code please to align wording in a cell such as:

If cell E1 is greater than 0 the wording in cell is aligned right,
other wise wording in cell is aligned left.

Thanks in advance

Ed English


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
ED ED is offline
external usenet poster
 
Posts: 8
Default Alignment

Thanks again

Ed English


On Tue, 21 Jun 2005 17:33:38 -0500, Dave Peterson
wrote:

To change the alignment, you're gonna need a macro. This doesn't go on the
worksheet itself.

This will adjust when you change something in column E.

Rightclick on the worksheet tab that should have this behavior. Select View
Code and paste this in the code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRng As Range
Dim myCell As Range

Set myRng = Intersect(Target, Me.Range("e:e"))

If myRng Is Nothing Then Exit Sub

On Error Resume Next
For Each myCell In myRng.Cells
If myCell.Value 0 Then
Me.Cells(myCell.Row, "C").HorizontalAlignment = xlRight
Else
Me.Cells(myCell.Row, "C").HorizontalAlignment = xlLeft
End If
Next myCell
On Error Goto 0

End Sub

ED wrote:

Thanks for the code..

I was not too clear in my original question, I'm working up a spread
sheet where I want the wording in column C cells to be aligned right
if there is a plus number value in the corresponding E cell, otherwise
the wording in column C is aligned left.

I thought that putting the following in C1:

=If(E10,myRng.HorizontalAlignment = xlRight,myRng.HorizontalAlignment
= xlLeft)

would set the alignment right in C1, then the the wording I put in C1
would be aligned right.

It doesn't seem to work. Any comments?

On Tue, 21 Jun 2005 13:21:17 -0500, Dave Peterson
wrote:

Since you're writing about wording, are you using e1 to control another cell?

If yes, how about something like:

Option Explicit
Sub testme01()

Dim myCell As Range
Dim myRng As Range

With ActiveSheet
Set myCell = .Range("e1")
Set myRng = .Range("f1")
End With

If myCell.Value 0 Then
myRng.HorizontalAlignment = xlRight
Else
myRng.HorizontalAlignment = xlLeft
End If

End Sub



ED wrote:

Code please to align wording in a cell such as:

If cell E1 is greater than 0 the wording in cell is aligned right,
other wise wording in cell is aligned left.

Thanks in advance

Ed English




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
In Cell alignment, how do I update the default vertical alignment How to update default cell alignment Setting up and Configuration of Excel 2 February 4th 09 02:25 PM
Right Alignment Paul Gauci New Users to Excel 0 August 18th 08 07:33 PM
Text alignment dkingfish Excel Discussion (Misc queries) 0 January 22nd 07 03:44 PM
Need some help with alignment havocdragon Excel Discussion (Misc queries) 1 August 27th 06 01:09 PM
Alignment Leah Excel Discussion (Misc queries) 0 November 22nd 05 06:36 PM


All times are GMT +1. The time now is 04:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"