View Single Post
 
Old 09-30-2013, 07:05 AM
BobBridges's Avatar
BobBridges BobBridges is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

The reason I asked is this: In order to give a program its starting directions, of course sometimes it's necessary to use InputBox. But if the "direction" is simply to tell the program what range, worksheet, workbook etc to work with, I prefer to let the user indicate that parameter by by positioning the cursor before starting the program. So rather than have the user start the program and then enter a date in InputBox (as an OP did here recently) so that the program can search for that date and use the resulting column for input, the user will usually find it easier to put the cursor somewhere in that column before starting the program, and let the program use the active cell to indicate the column.

But I don't like my programs to assume any more about the user's behavior than they have to. What if he positions the cursor, then absentmindedly swaps to another window before starting the macro? In that case Excel can tell, because ActiveCell tells us what cell is active within Excel. But what if I know which sheet is the critical one and the user doesn't happen to be looking at that sheet when the program starts? How do I tell then what cell is active in the critical sheet? ... or rather, which cell would be the active one if that sheet were active?

If there's no way to do it and I must be sure, then I can just activate the necessary sheet first. In fact, it isn't that hard to record which sheet is active, switch to the important one and then switch back before exiting the program, if necessary. But I thought I'd ask, because after all Excel knows, so I thought it might be available to VBA as well.
Reply With Quote