VB If statement that skips if nothing selected

aka_krakur

Active Member
Joined
Jan 31, 2006
Messages
438
I have a userform that for selections made by user there is VB written to send this info to certain fields on the Excel Spreadsheet:

here is an example of that code:
Code:
'Fill in Criteria as selected
'Device Code

Dim i As Long, N As Long, a()
With CriteriaForm1.DeviceCodeListBox

For i = 0 To DeviceCodeListBox.ListCount - 1
    If DeviceCodeListBox.Selected(i) Then
        ReDim Preserve a(N)
        a(N) = DeviceCodeListBox.List(i)
        N = N + 1
    End If
Next
End With

Sheets("ReportableQuery").Range("B6").Resize(, N) = a

There came up a scenario that if the user either intentionally or accidentally didn't select anything from the list box the VB Code will bail because it's looking for something to fille in Row 6 (Starting in field B6).

So is there a way to insert another if statment that if value = "" to skip?
 
You probably want IsDate.
Code:
If Not IsDate(txtDate.Value) Then
   Msgbox "Not a valid date."
End If
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

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