Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trigger makro in excel

Status
Not open for further replies.

cspm2003

Programmer
Nov 24, 2004
78
DE
Hi,

I have written an excel makro, thats supposed to get executed when a "1" is written in a cell. I dont write the "1" in there manually, a secound program does this. I used this code
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Address = "$G$2" Then
    If Target.Value = 1 Then
    call makro1
    End If
End If
End Sub

this works fine If I enter the "1" manually in the cell, but when the other program changes the cells value to "1" it doesnt work. Why is that and how would I fix it?

 
cspm2003,

This is the WORKBOOK Sheet Change event.

You should ALSO supply the Sheet Object in your code.

What this code means is that on ANY sheet, when a change is made to G2 AND the value is 1 then your macro runs. Is that what you want to happen

now for your question. What is the code for your second program that writes to G2?

Skip,

[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue]


 
Hi,

all he does is write the value in the cell, and nothing more, but Im going to ask him again tomrow and try out your code when Im at work.

thx
 
Hi Skip,

I certainly dont want this to happen on any sheet, just on scheet1. How would I have to change the code to work just for sheet1?

I dont know what code the secound program uses, one of my coworkers did that.
it supposed to work like this: he writes a "1" in the field, I do my calculation stuff, and when Im done he gets the results from the sheet. I thought that maybe the focus is still on G2 when he writes the "1" in the cell, so we wrote a "1" in a different cell aswell after that, but that didnt work either.
 
Well you have to know!

His code may turn off the event handler.
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  If Sh.Name = "Sheet1" And Target.Address = "$G$2" Then
    If Target.Value = 1 Then
       call makro1
    End If
  End If
End Sub


Skip,

[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue]


 
Hi Skip,

your code works, thanks for the tip!

I talked to him again, and he said all he does is write the code into the cell and nothing more
 
Try this...
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  If Sh.Name = "Sheet1" And Target.Address = "$G$2" Then
    If [b]cInt(Target.Value)[/b] = 1 Then
       call makro1
    End If
  End If
End Sub


Skip,

[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue]


 
Hi Skip,

sorry I didnt reply,but I had school and kinda forgot about work...

That code doesnt work either with the program. What I did now Is write a vbscript that calls the makro in the excel sheet. the other application doesnt write a one in the sheet, it just calls the vbscript. It aint that nice imo, but it works. if you have any other ideas please tell me, else thx for all your time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top