A
Annika
I am creating a macro in Excel that will be used by many
different users, each with their own worksheets, etc.
The macro is used to extract data from a worksheet that
they already have open, and then output new data in the
worksheet that the macro was activated in.
In my code I have an input box where I ask the user for
the name of the worksheet that contains the source data.
My question is, what if they type in an invalid worksheet
name? What code can I put in there so that the user
doesn't have to deal with VBA error messages?
For example, if the worksheet name is "Sheet1" and they
type "Sheet_1," I would like a message box to be
activated. I know how to activate a message box, I just
don't know how to code for the computer recognizing
whether or not a workwheet by that name exists, without it
going into VBA error message hell.
Here's a chunk of my code, to give you a better idea of my
problem.
*******************
'Ask user for source worksheet
HrlySheet = InputBox("Which sheet would you like to take
the hourly data from?", _
"Source Sheet", ActiveSheet.Name)
'If user clicks cancel or leaves field blank, exit Sub
If HrlySheet = "" Then Exit Sub
'Activate the source sheet
Sheets(HrlySheet).Activate
*******************
different users, each with their own worksheets, etc.
The macro is used to extract data from a worksheet that
they already have open, and then output new data in the
worksheet that the macro was activated in.
In my code I have an input box where I ask the user for
the name of the worksheet that contains the source data.
My question is, what if they type in an invalid worksheet
name? What code can I put in there so that the user
doesn't have to deal with VBA error messages?
For example, if the worksheet name is "Sheet1" and they
type "Sheet_1," I would like a message box to be
activated. I know how to activate a message box, I just
don't know how to code for the computer recognizing
whether or not a workwheet by that name exists, without it
going into VBA error message hell.
Here's a chunk of my code, to give you a better idea of my
problem.
*******************
'Ask user for source worksheet
HrlySheet = InputBox("Which sheet would you like to take
the hourly data from?", _
"Source Sheet", ActiveSheet.Name)
'If user clicks cancel or leaves field blank, exit Sub
If HrlySheet = "" Then Exit Sub
'Activate the source sheet
Sheets(HrlySheet).Activate
*******************