lucpian
04-10-2008, 03:12 PM
Hi,
I wrote a vba code that should basically check and see if there any cell that is not left aligned, and then aligned it. I am not getting any error, but it is not working either, and I have spent almost the entire day trying to figure out why it is not working. Here is the code, and I need the help of members of this forum.
Function Aligningcells(columnname As Integer)
Dim rowcount
Dim R
Dim Cells
rowcount = Range("A65536").End(xlUp).Row
For R = 2 To rowcount
If Sheet1.Cells(R, columnname).HorizontalAlignment = xlRight Then
' MsgBox "The cell(s) highlighted in blue is/are not align "
Sheet1.Cells(R, columnname).HorizontalAlignment = xlLeft
End If
If Sheet1.Cells(R, columnname).HorizontalAlignment = xlCenter Then
'MsgBox "The cell(s) highlighted in blue is/are not align "
Sheet1.Cells(R, columnname).HorizontalAlignment = xlLeft
End If
Next
End Function
Sub CheckFieldsAlignment()
Aligningcells (1)
Aligningcells (2)
Aligningcells (3)
Aligningcells (4)
Aligningcells (5)
Aligningcells (6)
Aligningcells (7)
Aligningcells (8)
Aligningcells (9)
Aligningcells (10)
Aligningcells (11)
Aligningcells (12)
Aligningcells (13)
Aligningcells (14)
Aligningcells (15)
Aligningcells (16)
Aligningcells (17)
Aligningcells (18)
Aligningcells (19)
End Sub
Thanks
Lucpian
I wrote a vba code that should basically check and see if there any cell that is not left aligned, and then aligned it. I am not getting any error, but it is not working either, and I have spent almost the entire day trying to figure out why it is not working. Here is the code, and I need the help of members of this forum.
Function Aligningcells(columnname As Integer)
Dim rowcount
Dim R
Dim Cells
rowcount = Range("A65536").End(xlUp).Row
For R = 2 To rowcount
If Sheet1.Cells(R, columnname).HorizontalAlignment = xlRight Then
' MsgBox "The cell(s) highlighted in blue is/are not align "
Sheet1.Cells(R, columnname).HorizontalAlignment = xlLeft
End If
If Sheet1.Cells(R, columnname).HorizontalAlignment = xlCenter Then
'MsgBox "The cell(s) highlighted in blue is/are not align "
Sheet1.Cells(R, columnname).HorizontalAlignment = xlLeft
End If
Next
End Function
Sub CheckFieldsAlignment()
Aligningcells (1)
Aligningcells (2)
Aligningcells (3)
Aligningcells (4)
Aligningcells (5)
Aligningcells (6)
Aligningcells (7)
Aligningcells (8)
Aligningcells (9)
Aligningcells (10)
Aligningcells (11)
Aligningcells (12)
Aligningcells (13)
Aligningcells (14)
Aligningcells (15)
Aligningcells (16)
Aligningcells (17)
Aligningcells (18)
Aligningcells (19)
End Sub
Thanks
Lucpian