Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-19-2016, 04:40 PM
olybobo olybobo is offline vba script to align text to the center Windows 7 64bit vba script to align text to the center Office 2010 64bit
Novice
vba script to align text to the center
 
Join Date: May 2016
Posts: 17
olybobo is on a distinguished road
Default 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
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
vba script to align text to the center Justify left center and right center on same line DiGug Word 3 10-02-2014 02:43 PM
vba script to align text to the center Unable to vertically center align texts in table cells? tinfanide Word 3 11-24-2013 06:37 AM
vba script to align text to the center How to align And center the content of the column in a table? Jamal NUMAN Word 1 05-02-2011 05:47 PM
Macro that will go to line # and center text marge Word VBA 0 09-10-2010 12:30 PM
vba script to align text to the center how to center text in multiple columns galiwock Excel 1 05-12-2010 09:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft