Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default AutoRun Macro Based on a Sum Calculation

I have recorded a few macros in Excel but I have very little expirence with
Visual Basic. I have written the following macro and it works great except
I would like to automatically run when the sum of "af1" gets below 10.

Sub Macro1()

Dim MyData As DataObject
Dim strClip As Integer

If Range("af1").Value 9 Then
Exit Sub
Else
Range("af1").Select
Selection.Copy
Range("A4:C29,D1:I9,J1:AC3").Select

Set MyData = New DataObject
MyData.GetFromClipboard
strClip = MyData.GetText

Selection.Replace What:=strClip, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("Af1,a1:c3").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Range("af1).ClearContents

End If

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default AutoRun Macro Based on a Sum Calculation

Place this code directly in the worksheet (right click the sheet tab and
select view code).

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range

On Error Resume Next
Set rng = Intersect(Target.Dependents, Range("A1F"))
On Error GoTo 0
If Not rng Is Nothing And _
Range("AF1") < 10 Then MsgBox "Call Macro 1"
End Sub
--
HTH...

Jim Thomlinson


"Jared J" wrote:

I have recorded a few macros in Excel but I have very little expirence with
Visual Basic. I have written the following macro and it works great except
I would like to automatically run when the sum of "af1" gets below 10.

Sub Macro1()

Dim MyData As DataObject
Dim strClip As Integer

If Range("af1").Value 9 Then
Exit Sub
Else
Range("af1").Select
Selection.Copy
Range("A4:C29,D1:I9,J1:AC3").Select

Set MyData = New DataObject
MyData.GetFromClipboard
strClip = MyData.GetText

Selection.Replace What:=strClip, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("Af1,a1:c3").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Range("af1).ClearContents

End If

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default AutoRun Macro Based on a Sum Calculation

Sorry you should turn off the events while the code is running like this...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range

on error goto ErrorHandler
application.enableevents = false

On Error Resume Next
Set rng = Intersect(Target.Dependents, Range("A1F"))
On Error GoTo 0
If Not rng Is Nothing And _
Range("AF1") < 10 Then MsgBox "Call Macro 1"
ErrorHandler:
application.enableevents = true
End Sub

--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

Place this code directly in the worksheet (right click the sheet tab and
select view code).

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range

On Error Resume Next
Set rng = Intersect(Target.Dependents, Range("A1F"))
On Error GoTo 0
If Not rng Is Nothing And _
Range("AF1") < 10 Then MsgBox "Call Macro 1"
End Sub
--
HTH...

Jim Thomlinson


"Jared J" wrote:

I have recorded a few macros in Excel but I have very little expirence with
Visual Basic. I have written the following macro and it works great except
I would like to automatically run when the sum of "af1" gets below 10.

Sub Macro1()

Dim MyData As DataObject
Dim strClip As Integer

If Range("af1").Value 9 Then
Exit Sub
Else
Range("af1").Select
Selection.Copy
Range("A4:C29,D1:I9,J1:AC3").Select

Set MyData = New DataObject
MyData.GetFromClipboard
strClip = MyData.GetText

Selection.Replace What:=strClip, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("Af1,a1:c3").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Range("af1).ClearContents

End If

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default AutoRun Macro Based on a Sum Calculation

Thanks Jim for the reply, but it does not seem to work like I envisioned it.
I have a sum formula in af1 and as cells in the range get deleted the sum in
af1 will decrease to a number between 1 & 9 and as soon as that happens I
would like excel to run Macro 1 automatcally. Once Macro 1 runs, it will
delete the sum formula in af1 so it does not continously run. I have looked
through alot of posts on this group and others but I can not seem to find
someone with the same issue. Maybe I am asking too much of excel.


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
macro to go to cell based upon a calculation MARK M Excel Discussion (Misc queries) 7 November 30th 08 01:28 AM
Autorun macro Kelly Excel Worksheet Functions 1 January 18th 06 04:03 PM
Excel Macro Issue Trying to autorun Macro Upon Opening Worksheet wyndman Excel Programming 2 May 25th 04 06:59 PM
Autorun a macro Nigel Chapman Excel Programming 1 February 4th 04 01:02 PM
autorun a macro Reab Excel Programming 1 November 28th 03 09:42 PM


All times are GMT +1. The time now is 02:39 PM.

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

About Us

"It's about Microsoft Excel"