easiest question ever

cocopops2001

Board Regular
Joined
Apr 18, 2011
Messages
112
i have a userform with a dropdown box which allows a user to select an open workbook, when they click OK some code runs.

when they click OK without a file selected i get a runtime error 13, type mismatch.

what do i have to add to tell it to do nothing if a file is not selected.

i am thinking something like:

Code:
if myfile = "" then
'''its this bit i dont know what to write.

the code for the button click is here
Code:
Private Sub CommandButton1_Click()
    
    Dim Myfile As String
        
    Myfile = ComboBox1.Value
    
    '''opens new book
    Workbooks(Myfile).Activate
        
    '''''checks if cover sheet exists and if not creates one
    covercheck
    
    ''''copies desired sheet
    ThisWorkbook.ActiveSheet.Range("a11:n70").Copy
    
    '''''copies desired sheet
    sheetcopy
     
    UserForm3.Hide
    
End Sub

thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Maybe something like this...
Code:
If myfile = "" Then
    MsgBox "Why did you click the OK button? You did not select a workbook to activate yet!"
    Exit Sub
End If
 
Upvote 0

Forum statistics

Threads
1,224,578
Messages
6,179,654
Members
452,934
Latest member
mm1t1

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