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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,215,429
Messages
6,124,835
Members
449,192
Latest member
mcgeeaudrey

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