Various Text alignment in one code

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Partial piece of code supplied for you

My range is N4:R4

Assuming i would like the Text alignment Center ".HorizontalAlignment = xlCenter" for cells O4:R4 only as cell N4 needs to be Text alignment Left ".HorizontalAlignment = xlLeft"
Please advise how the code below should then look.

Thanks


Rich (BB code):
        End If

        LastRow = .Cells(Rows.Count, "N").End(xlUp).Row + 1
       
        Application.ScreenUpdating = False
        For i = 1 To 5
            With .Cells(LastRow, i + 13)
                .Value = Me.Controls("TextBox" & i).Value
                .Font.Name = "Calibri"
                .Font.Size = 11
                .Font.Bold = True
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlCenter
                .Borders.Weight = xlThin
                .Interior.ColorIndex = 6
            End With
            
        Next i
        Application.ScreenUpdating = True
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Here:
VBA Code:
        Application.ScreenUpdating = False
        For i = 1 To 5
            .Cells(LastRow, i + 13).Value = Me.Controls("TextBox" & i).Value
        Next i
        .Cells(LastRow, "N").HorizontalAlignment = xlLeft
        With .Cells(LastRow, 14).Resize(,5)
            .Font.Name = "Calibri"
            .Font.Size = 16
            .Font.Bold = True
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .Borders.Weight = xlThin
        End With
        Application.ScreenUpdating = True
 
Upvote 0
Hi,
Thats not what i meant,maybe i didnt explain correctly.

Cell N4 = Text Alignment Left
Cell O4 = Text Alignment Center
Cell P4 = Text Alignment Center
Cell Q4 = Text Alignment Center
Cell R4 = Text Alignment Center

The code in post #2 is ALL CENTER

See attached photo please
 

Attachments

  • 1725.jpg
    1725.jpg
    13.6 KB · Views: 3
Upvote 0
It's my blunder. Try this:
VBA Code:
        Application.ScreenUpdating = False
        For i = 1 To 5
            .Cells(LastRow, i + 13).Value = Me.Controls("TextBox" & i).Value
        Next i
        With .Cells(LastRow, "N").Resize(,5)
            .Font.Name = "Calibri"
            .Font.Size = 16
            .Font.Bold = True
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .Borders.Weight = xlThin
        End With
        .Cells(LastRow, "N").HorizontalAlignment = xlLeft
        Application.ScreenUpdating = True
 
Upvote 0
Solution

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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