Run a Userform combobox code only if it is not empty

MIRA7

New Member
Joined
Dec 19, 2016
Messages
25
I have a userform code that it runs perfect but it is very slow, and trying to make it run faster.

When I ran the code below, all combobox/optionbutton that have values in it show as TRUE on the overall sheet (Column A), or else if blank, it show false.

Instead of having all these line run one by one (it takes forever), I m trying to find a code to make it run only if the combobox is not blank (TRUE), and make the rest automatically show false on the overall sheet itself.

The intend is to make the code run faster.

Code:
Private Sub CommandButton1_Click()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False

Dim ws As Worksheet
Set ws = Worksheets("Overall")
  'copy the data to the database
With ws
.Cells(2, 1).Value = Me.SJ1.Value
.Cells(92, 1).Value = Me.SJ2.Value
.Cells(182, 1).Value = Me.SJ3.Value
.Cells(272, 1).Value = Me.SJ4.Value
.Cells(362, 1).Value = Me.SJ5.Value
.Cells(452, 1).Value = Me.SJ6.Value
.Cells(542, 1).Value = Me.SJ7.Value
.Cells(632, 1).Value = Me.SJ8.Value
.Cells(722, 1).Value = Me.SJ9.Value
.Cells(812, 1).Value = Me.SJ10.Value
.Cells(902, 1).Value = Me.SJ11.Value
.Cells(992, 1).Value = Me.SJ12.Value
.Cells(1082, 1).Value = Me.SJ13.Value
.Cells(1172, 1).Value = Me.SJ14.Value
.Cells(1262, 1).Value = Me.SJ15.Value

ActiveWorkbook.Save

Application.EnableEvents = True
Application.DisplayStatusBar = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
  
Unload Me

End With

End Sub

This is only one portion of the code, but I do have a lot of lines with combobox.optionbutton.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
How is the posted code linked to the ccombobox(es)?
 
Upvote 0
Here is how it is linked.

Code:
Private Sub UserForm_Initialize()
   Dim Ary As Variant
   Dim Cnt As Long
   
   Ary = Sheets("Cover").Range("G6", Sheets("Cover").Range("G6").End(xlDown))
   For Cnt = 1 To 15
      Me.Controls("SJ" & Cnt).List = Ary
   Next Cnt
   
End Sub

I tried to add this before and after the code to make it run faster, but it is still slow.
Code:
Debug.Print Time
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False

code here

Application.EnableEvents = True
Application.DisplayStatusBar = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
 
Upvote 0

Forum statistics

Threads
1,215,987
Messages
6,128,129
Members
449,425
Latest member
NurseRich

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