Code doesnt appear in cell as it should

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,908
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Please could you take a look at my code and advise what i have done wrong.

I select an option button on a userform & transfer oit to my worksheet, This works fine.

What i need to do it format then the value in the cell I9 Bold Calibri etc etc but this is the part that has no affect.

Rich (BB code):
Private Sub CommandButton1_Click()
    
 With ThisWorkbook.Worksheets("RANGER")
    If OptionButton3.Value = True Then .Cells(lastrow + 5, 9).Value = "N 41601-501-41": OptionButton3.Value = False
    If OptionButton4.Value = True Then .Cells(lastrow + 5, 9).Value = "N 41803-501-42": OptionButton4.Value = False
    If OptionButton5.Value = True Then .Cells(lastrow + 5, 9).Value = "V 41803-501-43": OptionButton5.Value = False
 End With
 
    Range("I9").Font.Size = 14
    Range("I9").Font.Name = "Calibri"
    Range("I9").Font.Bold = True
    Range("I9").HorizontalAlignment = xlCenter
    Range("I9").VerticalAlignment = xlVAlignCenter
    Unload RangerPcbNumber
    
End Sub
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,977
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
It is formatting I9 on the ActiveSheet because you haven't referenced/specified the sheet for it to act on.
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,484
Office Version
  1. 2019
Platform
  1. Windows
Range I9 is unqualified - try following update to your code


VBA Code:
Private Sub CommandButton1_Click()
    
 With ThisWorkbook.Worksheets("RANGER")
    If OptionButton3.Value = True Then .Cells(lastrow + 5, 9).Value = "N 41601-501-41": OptionButton3.Value = False
    If OptionButton4.Value = True Then .Cells(lastrow + 5, 9).Value = "N 41803-501-42": OptionButton4.Value = False
    If OptionButton5.Value = True Then .Cells(lastrow + 5, 9).Value = "V 41803-501-43": OptionButton5.Value = False
 
 
    With .Range("I9")
        .Font.Size = 14
        .Font.Name = "Calibri"
        .Font.Bold = True
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlVAlignCenter
    End With
    
End With
    Unload RangerPcbNumber
    
End Sub

Dave
 
Solution

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,908
Office Version
  1. 2007
Platform
  1. Windows
Thanks i now see my mistake.

Also I9 should of been I5

Thanks
 

Watch MrExcel Video

Forum statistics

Threads
1,127,554
Messages
5,625,474
Members
416,109
Latest member
TripleA00123

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
Top