formating current row to center text

  • Thread starter Thread starter tim
  • Start date Start date
T

tim

I need the correct code for selecting and centering text
in the current row or from row current-1 to current +3

the code below centers the text in each cell entire
spreadsheed.

For lngROW = 3 To Rng.Rows.Count
cellchar = Cells(lngROW, 1).Value
If Mid(cellchar, 1, 10) = "==========" Then
ActiveWindow.SelectedSheets.HPageBreaks.Add
Before:=Cells(lngROW + 1, 1)
Application.StatusBar = "Row: " + Format(lngROW)
ElseIf Mid(cellchar, 1, 6) = "Agency" Then
For begROW = lngROW - 1 To lngROW + 3
Rows().Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Next begROW
End If
Next lngROW
 
Because you have not specified any row in your command
Rows().Select
all rows are selected

Try



For lngROW = 3 To Rng.Rows.Count
cellchar = Cells(lngROW, 1).Value
If Mid(cellchar, 1, 10) = "==========" Then
ActiveWindow.SelectedSheets.HPageBreaks.Add
Before:=Cells(lngROW + 1, 1)
Application.StatusBar = "Row: " + Format(lngROW)
ElseIf Mid(cellchar, 1, 6) = "Agency" Then
Rows(lngROW - 1 & ":" & lngROW + 3).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
End If
Next lngRO
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top