How to justify excel cells?
Posted on 2004-04-26
I have a simple VB program that reads in a text file, maniputes the data fields, and writes out an excel spreadsheet. Up until now, if I wanted to left-justify a cell value, I would precede it with a quote mark. That seems to work fine, as excel apparently sees it as the old Lotus convention of quote for LJ. But supposedly excel should also see a leading ^ to mean centering, and a " to mean right justify. However, I can't get these two to work.
Is there an easy way to make it center or RJ, using a preceding character as described above?
If not, I need help on making justification work the 'right way'. I have looked at some of the answers posted previously, but being new to vb, I just don't understand where and how I would insert the proper syntax. Below I will show examples of some of the statements I am using, so maybe someone can tell me how to do this:
ExcelApp.Visible = True
Private Sub WriteToSheet(By Val intRow As Integer, By Val strA as String, By val strB as String)
.Range("A1").Value = "CITY"
.Range("B1").Value = "STATE"
ExcelApp.Workbooks(1).Worksheets(1).Name = "Locality"
.Range("A" & introw.ToString.Trim).value = strA
.Range("B" & introw.ToString.Trim).value = strB
...and from there, I go on to define the values of strA and strB, and then I:
WriteToSheet(intRow, strA, strB)
My question is this: exactly how and where would I define the excel cell justification characteristics when I write out values for strA and strB? For example, how would I make strA LJ (left-justify), while strB is RJ?