vba script to align text to the center
ello experts;
Please help. I have googled this and tried so many solutions. I am using excel 2010. I am not sure whether this is a bug or not. Can someone please see my code below. I would like to write a vba code that gets ran after a pivot table refresh. the code is meant to center the text in column e. see my code below. it is not centering the text in column e and i do not know why.
Sub req_alignment()
End Sub
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim myRange As Range
Dim cellContent As String
Dim cellLen As Integer
Set myRange = Range("E:E")
If Not Intersect(Target, myRange) Is Nothing Then
cellContent = Target
cellLen = Len(cellContent)
If (cellLen < 5) Then
Target.HorizontalAlignment = xlCenter
Else
Target.HorizontalAlignment = xlLeft
End If
End If
End Sub
|