Bold & Centre Aligned

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Bold & Centre Aligned

Post by adam »

The following code inserts text rows when the list box is double clicked.

How could I make the code to insert the texts in center aligned and bold to the appropriate sheet rows mentioned in the code.

Any help on this would be kindly appreciated.

Thanks in advance.

Code: Select all

Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  Dim r As Long
  With Worksheets("NewOrder")
    If Range("F14") = "" Then
      r = 14
    Else
      r = .Range("F13").End(xlDown).Row + 1
    End If
    .Range("F" & r) = Me.ListBox2.Column(0)
  End With
End Sub
Best Regards,
Adam

User avatar
rory
5StarLounger
Posts: 818
Joined: 24 Jan 2010, 15:56

Re: Bold & Centre Aligned

Post by rory »

Code: Select all

With .Range("F" & r)
   .Value = Me.ListBox2.Column(0)
   .font.Bold = True
   .horizontalalignment = xlHaligncenter
End With
Regards,
Rory

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Bold & Centre Aligned

Post by HansV »

Change the line

Code: Select all

    .Range("F" & r) = Me.ListBox2.Column(0)
to

Code: Select all

    With .Range("F" & r)
        .Value = Me.ListBox2.Column(0)
        .HorizontalAlignment = xlCenter
        .Font.Bold = True
    End With
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Bold & Centre Aligned

Post by adam »

Thanks for the help Rory & Hans. It worked fine.
Best Regards,
Adam