PDA

View Full Version : VBA knowing which cells it has filled?



karrotman
07-25-2012, 11:55 AM
Since a VBA function unlike a sub allows you to select the cells you want, place the function in the bar on top, and then press CTRL+SHFT+ENTR to populate, is there a way for VBA without actually exiting the code to figure out which cells were populated?


For example, would I be able to run a sub right before exiting the function which would determine which cells have been populated?


Thanks!

Kenneth Hobs
07-25-2012, 02:31 PM
You can use the sheet's Selection event or Application.OnKey.

e.g.
Sub SetOnKey()
MsgBox Selection.Address
End Sub

Sub SetOnKey_()
Application.OnKey "^+{RETURN}", "SetOnKey"
End Sub