Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column and row formatting in Excel via VBA

Status
Not open for further replies.

MCubitt

Programmer
Joined
Mar 14, 2002
Messages
1,081
Location
GB
Can someone please tell me how to set a cell to use text orientation of 90 degrees (so the writing is)

s
i
h
t

not

this

I just cannot find the VBA command.

Also, I cannot get the right format to justify a column text.

I have
Code:
Sheets("users to add to core").Columns(placedcol).HorizontalAlignment = "xl" & Cells(7, mastercol)

Cells(7,mastercol) will be Left, center ro right

I get run time 1004, unable to set the horizontal property of range class


Thanks


Applications Support
UK
 
Hi MCubitt,

Have you tried [blue][tt][A1].Orientation = 90[/tt][/blue]?

Your second problem: you can't code like that at all, I'm afraid. xlLeft, etc., are VBA constants and they don't even equate to numbers you could easily code instead. You will need to use some conditional logic - a Case construct perhaps, Or an If .. ElseIf ,, Else

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
I may be setting myself up for a fall here but I've just managed to set the alignments using the constant values which are as follows:-

left = -4131
right = -4152
center = -4108
justify = -4130
center across selection = 7

Which you might be able to use.......


;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
Thanks both of you, that's cool.

The orientation is too obvious, shurely shome mishtake! Thanks, couldn't find it in the help.. amongst the other stuff!

As for the alignment.. doh! I'll use the case idea, thanks.






Applications Support
UK
 
Worked a treat thanks, and how may I set teh height of rows 2 - 65535 (ie all but the top) please?

Oh, the case is here:
Code:
    Select Case Cells(7, mastercol).Value
    Case "Left"
      Sheets("users to add to core").Columns(placedcol).HorizontalAlignment = xlLeft
    Case "Right"
      Sheets("users to add to core").Columns(placedcol).HorizontalAlignment = xlRight
    Case "Centre"
      Sheets("users to add to core").Columns(placedcol).HorizontalAlignment = xlCenter
    End Select

thanks


Applications Support
UK
 
Hi MCubitt,

[blue][tt]Sheet1[/tt][tt].Rows("2:65535").RowHeight = 22[/tt][/blue][green][tt] ' However big you want them [/tt][/green]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top