首页 > 解决方案 > Using a MsgBox and If Then to open another worksheet

问题描述

I'm trying to write a code that if an individual clicks "Yes" on the popup msgbox that they are directed to another worksheet and specific cell.

My question is if it's possible to have multiple msgboxes based on a selected cell? If someone was to select E34 having it popup the correct corresponding msgbox? While using an If Then to direct to the correct page/cell?

All the worksheets are within in one workbook document.

Sub PopupBox()

    Dim answer As Integer

    answer = MsgBox("Add Comments or Images to Category?", vbYesNo + vbQuestion, "Comment")

    If answer = vbYes Then

    ActiveWorkbook.Sheets("Comments").Range ("B7")

    Else
        'do nothing
    End If

End Sub

标签: excelvba

解决方案


如果要选择该单元格,则需要首先激活工作表:

ActiveWorkbook.Sheets("Comments").Activate
ActiveWorkbook.Sheets("Comments").Range("B7").Select

推荐阅读