Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Execute macro when active cell is in a defined area

Perfect

Many thanks


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
run macro although blinking cursor is active in an active cell bartman1980 Excel Programming 1 December 20th 07 11:29 AM
The Defined Name of An Active Cell Arishy[_2_] Excel Programming 3 September 2nd 05 05:35 AM
Auto execute a macro if a cell value=1 ? Sven[_5_] Excel Programming 1 November 15th 04 02:33 PM
Auto execute a macro if a cell value=1 ? Sven[_4_] Excel Programming 1 November 14th 04 11:36 PM
Auto execute a macro if a cell value=1 ? Sven[_2_] Excel Programming 3 May 16th 04 12:06 AM


All times are GMT +1. The time now is 07:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"