A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Centreing Text In Excel Cells



 
 
Thread Tools Display Modes
  #1  
Old April 22nd, 2010, 03:42 PM posted to microsoft.public.excel.worksheet.functions
Alan
external usenet poster
 
Posts: 459
Default Centreing Text In Excel Cells

I am send data to an Excel Spreadsheet, which includes some numeric data and
some text data.

I want to have the text in all columns in the centre of the cell. I have
tried lots of different code:-

xlSheet.Range("A:L").HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Cells.HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Columns.HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Cells(10, 1).HorizontalAlignment = HorizontalAlignment.Left
xlSheet.Columns("C").HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Range("A6:L15").HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Cells.HorizontalAlignment = True
xlSheet.Range("A6:L15").HorizontalAlignment = HorizontalAlignment.Center

but nothing seems to work.

If I use horizontalalignment.left the code will not work and I get error
reports.
If I use horizontalalignment.right all the cells requested are aligned to
the left.
If I use horizontalalignment.center the cells are as you would see in a
spreadsheet,
numeric on the right and text on the left of the cell.

All other forms of formatting, i.e. Font.Size, Font.Bold, BorderAround all
work.
The data is being sent to Excel 2000, may seem a bit archaic but it is only
being used to give a direct printout of the data, easier than formatting it
into a document.
--
Alan M
  #2  
Old April 22nd, 2010, 04:01 PM posted to microsoft.public.excel.worksheet.functions
Duke Carey
external usenet poster
 
Posts: 1,027
Default Centreing Text In Excel Cells

Alan -

Maybe

xlSheet.Range("A:L").HorizontalAlignment = xlCenter


"Alan" wrote:

I am send data to an Excel Spreadsheet, which includes some numeric data and
some text data.

I want to have the text in all columns in the centre of the cell. I have
tried lots of different code:-

xlSheet.Range("A:L").HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Cells.HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Columns.HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Cells(10, 1).HorizontalAlignment = HorizontalAlignment.Left
xlSheet.Columns("C").HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Range("A6:L15").HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Cells.HorizontalAlignment = True
xlSheet.Range("A6:L15").HorizontalAlignment = HorizontalAlignment.Center

but nothing seems to work.

If I use horizontalalignment.left the code will not work and I get error
reports.
If I use horizontalalignment.right all the cells requested are aligned to
the left.
If I use horizontalalignment.center the cells are as you would see in a
spreadsheet,
numeric on the right and text on the left of the cell.

All other forms of formatting, i.e. Font.Size, Font.Bold, BorderAround all
work.
The data is being sent to Excel 2000, may seem a bit archaic but it is only
being used to give a direct printout of the data, easier than formatting it
into a document.
--
Alan M

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:47 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.