![]() |
Execute macro when active cell is in a defined area
Hi all
I am completely inept at writting code for macros - most of my stuff is for repetitive task such as cut copy & paste For one such macro is there any way a code can be added so that the macro will only execute if the active cell is in a defined range say A1:G10 but if the active cell is not in this range go make cell A1 active?? Much appreciated |
Execute macro when active cell is in a defined area
Option Explicit
Sub testme() if intersect(activecell, activesheet.range("a1:g10")) is nothing then activesheet.range("a1").select exit sub end if 'rest of macro here end Sub (Untested, uncompiled--watch for typos) Spuds Glorious Spuds wrote: Hi all I am completely inept at writting code for macros - most of my stuff is for repetitive task such as cut copy & paste For one such macro is there any way a code can be added so that the macro will only execute if the active cell is in a defined range say A1:G10 but if the active cell is not in this range go make cell A1 active?? Much appreciated -- Dave Peterson |
Execute macro when active cell is in a defined area
Sub dural()
If Intersect(ActiveCell, Range("A1:G10")) Is Nothing Then Range("A1").Select Else MsgBox ("do your thing") End If End Sub Substitute the body of your own code where the MsgBox is. -- Gary''s Student - gsnu200834 "Spuds Glorious Spuds" wrote: Hi all I am completely inept at writting code for macros - most of my stuff is for repetitive task such as cut copy & paste For one such macro is there any way a code can be added so that the macro will only execute if the active cell is in a defined range say A1:G10 but if the active cell is not in this range go make cell A1 active?? Much appreciated |
Execute macro when active cell is in a defined area
Perfect
Many thanks |
All times are GMT +1. The time now is 11:32 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com