VBA code for message box and focus on a sheet

  • Thread starter Thread starter Thulasiram
  • Start date Start date
T

Thulasiram

Hello people,

I have a msgbox like this.

MsgBox "Please click the command button on the sheet7", vbInformation,
"Author"

I require the VB code for the following:
If the user presses the OK button of the msbox above, then the sheet7
must be shown on the screen. (like in VB6 (for example), form7.show)

what would be the VBA code for that..

please help..

Thanks,
Thulasiram
 
ans = MsgBox( "Please click the command button on the sheet7", _
vbInformation + vbOKCancel, "Author")
if ans = vbOk then
Worksheets("Sheet7").Activate
end if

assuming Sheet7 is the tab name. If it is the code name then

Sheet7.Activate
 
Dear Tom,

I am facing a compile error:
Variable not defined.. Variable referred here is "ans"

I tried ur code in a new excel file. It works. But, I am trying to
embed the code in

Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVal
target As Range)

So i have to declare the variable 'ans'

So I gave a declaration
dim ans as boolean

but in this case: Runtime error '13': Type mismatch..

Please provide your help to fix this error.

Thanks,
Thulasiram
 
dim ans as Long

--
Regards,
Tom Ogilvy


Thulasiram said:
Dear Tom,

I am facing a compile error:
Variable not defined.. Variable referred here is "ans"

I tried ur code in a new excel file. It works. But, I am trying to
embed the code in

Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVal
target As Range)

So i have to declare the variable 'ans'

So I gave a declaration
dim ans as boolean

but in this case: Runtime error '13': Type mismatch..

Please provide your help to fix this error.

Thanks,
Thulasiram
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top