excel - 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
解决方案
如果要选择该单元格,则需要首先激活工作表:
ActiveWorkbook.Sheets("Comments").Activate
ActiveWorkbook.Sheets("Comments").Range("B7").Select
推荐阅读
- javascript - 将随机且不存在的项目从另一个数组添加到数组
- reactjs - 根据查询字符串参数初始化存储
- google-cloud-speech - 带有 FLAC 的 Google Cloud Speech Streaming API
- javascript - 自动导入具有相同文件后缀的模块
- isabelle - 从具体对象实例化一个类?
- python - Keras 1.2.2 和 Keras 2.2 预测的差异
- c# - ASP.NET Core Web API 中的自定义操作
- laravel - 当模型更新作为计划任务运行时,Laravel 自定义事件不会被 eloquent 事件触发
- sharepoint - 使用 Sharepoint 作为 QnA Maker 的源
- python - raw_input 没有正确返回