Proper syntax for horizonal alignment within a column

pelkbc5172

New Member
Joined
Jan 3, 2025
Messages
2
Office Version
  1. 2011
Platform
  1. Windows
  2. Web
Hi Board members;

I haven't been coding for a while now and have been frustrated by the above topic. I have queried on the web numerous times today using "Excel VBA" followed by a space, with various topic queries and have made progress but the code I last found for horizontal alignment isn't working and I have certainly tried to use other approaches I found on the web and within my previous macros to solving the problem but they didn't work. While stepping through the code shown below using the F8 key, I can see column R - (offset,01) from Col Q - being populated properly but the Horizontal Alignment within Column R isn't working. I have gotten stuck at this point and would greatly appreciate some help achieving horizonal alignment within column R.

VBA Code:
Option Explicit

Dim q, ColQ As Range, ThisWorkbook, WSA As Worksheet, Dept, FndSrc, BCacct As String, LastRowA As Integer

Public Sub ProcessColQ()

Set WSA = Worksheets("2024 Easter Seals Adults, Pont")
LastRowA = Cells(Rows.Count, 1).End(xlUp).Row

Set ColQ = WSA.Range(Cells(2, 17).Address, Cells(LastRowA, 17).Address) 'Contains Full String A/C Number

For Each q In ColQ 'Contains the String A/C

FndSrc = Mid(q, 4, 3) 'Fund Source
Dept = Mid(q, 8,,4)    'Department Number
BCacct = Right(q,5)  'The 5 digit Business Central (GL) Account

If BCacct = "80835" Then
   q.Offset(0, 1) = "CCBHC - Medicaid"
ElseIf BCacct = "80031" Then
   q.Offset(0, 1) = "Medicaid - SUD - Outpatient"
ElseIf BCacct = "80032" Then
   q.Offset(0, 1) = "Medicaid - SUD - Case Mgmt"
ElseIf BCacct = "80837" Then
   q.Offset(0, 1) = "TCM"
ElseIf BCacct = "80949" Then
   q.Offset(0, 1) = "Child Autism"
ElseIf BCacct = "80845" Then
   q.Offset(0, 1) = "CCBHC - HMP"
ElseIf BCacct = "80855" Then
   q.Offset(0, 1) = "CCBHC Non-Medicaid"

End If

With WSA.Range("R1")
   .EntireColumn.AutoFit
   .HorizontalAlignment = xlCenter
End With

Next q

End Sub

Thanks in advance.

Brian
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Delete:
VBA Code:
With WSA.Range("R1")
   .EntireColumn.AutoFit
   .HorizontalAlignment = xlCenter
End With
After the Next q, insert:
VBA Code:
With WSA.Range("R1").EntireColumn
   .AutoFit
   .HorizontalAlignment = xlCenter
End With
 
Upvote 1
Solution
Delete:
VBA Code:
With WSA.Range("R1")
   .EntireColumn.AutoFit
   .HorizontalAlignment = xlCenter
End With
After the Next q, insert:
VBA Code:
With WSA.Range("R1").EntireColumn
   .AutoFit
   .HorizontalAlignment = xlCenter
End With
Thanks so much John-w!
 
Upvote 0

Forum statistics

Threads
1,225,362
Messages
6,184,514
Members
453,237
Latest member
lordleo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top