开发者

Same column in two worksheets are aligned differently horizontally

I am copying a worksheet programmatically by filling in a blank sheet. One column is a dollar amount. In the original sheet, it's right aligned. In the new sheet, it's left aligned. When I do format cells to look at the format, both are Number tab = General and horizontal alignme开发者_Python百科nt = General.

What's making them have two different kinds of horizontal alignments? I am assuming it's inferring the data type from the original one. How can I do the same in Excel for the other?


If the Number Format of the cell is General and Alignment hasn't been specifically set to anything, then text gets left-aligned and numbers get right-aligned.

However, you can deliberately set the alignment of any range, independently of the number formatting.

For example:

ActiveWorkbook.Worksheets("MyWorksheetName").Range("A1").HorizontalAlignment = xlRight

or

ActiveSheet.Range("B2:C7").HorizontalAlignment = xlCenter

or

ActiveCell.EntireColumn.HorizontalAlignment = xlLeft

Feel free to post some code if you need more detailed help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜