ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cell and Worksheet Location (https://www.excelbanter.com/excel-programming/412347-cell-worksheet-location.html)

glenn

Cell and Worksheet Location
 
I need to establish (programatically find) the activeworksheet and active or
selected cell at the start of a macro I need to write. I need to validate
that the user of the macro is in the right sheet and column and row range
before I run the rest of the macro code.

StumpedAgain

Cell and Worksheet Location
 
This should do the trick:

Option Explicit
Sub Right_Location()

Dim sheetname As String
sheetname = ActiveSheet.Name

If vbNo = MsgBox(sheetname & " " & ActiveCell.Address & ": Is this the
correct starting location?", vbYesNo) Then
MsgBox ("Please select the correct starting location.")
End
End If

End Sub



"Glenn" wrote:

I need to establish (programatically find) the activeworksheet and active or
selected cell at the start of a macro I need to write. I need to validate
that the user of the macro is in the right sheet and column and row range
before I run the rest of the macro code.


merjet

Cell and Worksheet Location
 
Suppose you want "Sheet1" and cell A5 to be the active ones.

If ActiveSheet.Name < "Sheet1" Or _
ActiveCell.Address < "$A$5" Then
MsgBox "Blah blah" 'optional
Exit Sub
End If


glenn

Cell and Worksheet Location
 
Thanks very much. I believe I'm good to go.

"StumpedAgain" wrote:

This should do the trick:

Option Explicit
Sub Right_Location()

Dim sheetname As String
sheetname = ActiveSheet.Name

If vbNo = MsgBox(sheetname & " " & ActiveCell.Address & ": Is this the
correct starting location?", vbYesNo) Then
MsgBox ("Please select the correct starting location.")
End
End If

End Sub



"Glenn" wrote:

I need to establish (programatically find) the activeworksheet and active or
selected cell at the start of a macro I need to write. I need to validate
that the user of the macro is in the right sheet and column and row range
before I run the rest of the macro code.



All times are GMT +1. The time now is 06:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com