Trigger a custom function in a Zoho Sheet on range change

Trigger a custom function in a Zoho Sheet on range change

Hello,

I have a custom function in Zoho Sheet that updates a Zoho CRM record. That by itself works. I am trying to trigger that function when a new row is added to the sheet. I thought this would be able to happen via the VBA editor, but I can't get it to work. It did work when the cells were hard coded, but then when using offset I couldn't get it to work. 

I have pretty much no experience with VBA. But here is what worked:


REM Sheet Module

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = false
On Error Goto ENEV
REM add your code below

Set watchRange = Range("L2:L1000")

If Not Intersect(Target,watchRange) Is Nothing Then

  If Target.Value <> Nothing Then

    Range(M2).Select
    ActiveCell.Formula="=_CREATE_UPDATE_OPP(A2,C2,D2)"

 End If 

  End If 

ENEV:
Application.EnableEvents = true
End Sub


When I attempted to enter offsets, so that it would get the values from the newly added row, I had no luck. No idea what I'm doing, just tried to use offset as I read about it in another article. 

Didn't work: 


REM Sheet Module

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = false
On Error Goto ENEV
REM add your code below

Set watchRange = Range("L2:L1000")

If Not Intersect(Target,watchRange) Is Nothing Then

  If Target.Value <> Nothing Then

    Range((Target.Value).Offset(0,1)).Select
   ActiveCell.Formula="=_CREATE_UPDATE_OPP(Target.Value.Offset(0,-11),Target.Value.Offset(0,-9),Target.Value.Offset(0,-8)"
 End If 

  End If 

ENEV:
Application.EnableEvents = true
End Sub


I also tried () around each offset reference. There is probably a way better way to do this, so if so, disregard what I've started. Thank you for your help!

      • Sticky Posts

      • Introducing a smarter, faster, and more flexible charting experience

        Hello Zoho Sheet users, We're delighted to share the latest news about a major update to charts in Zoho Sheet! The new version supports dynamic data ranges, granular styling options, faster loading, and other interesting enhancements that allow you to
      • What's new in Zoho Sheet: Simplify data entry and collaboration

        Hello, Zoho Sheet community! Last year, our team was focused on research and development so we could deliver updates that enhance your spreadsheet experience. This year, we’re excited to deliver those enhancements—but we'll be rolling them out incrementally
      • New Features: Repeat Last Action, Insert Cut/Copied Rows/Columns and Hyperlink

        You might have noticed the constant updates to Zoho Sheet of late. Here are 3 more features that have been added to Zoho Sheet recently: F4 - Repeat Last Action Insert Cut/Copied Rows and Columns Insert Hyperlink Here is a screen cast demonstrating each of these features. Read further below to learn more about these new features. F4 - Repeat Last Action: You can now repeat the last action you made on your spreadsheet by using the keyboard shortcut, F4. It is quite handy and helps you get your work
      • Introducing Forms in Zoho Sheet

        We hereby bring you the power of ​forms in Zoho Sheet. ​Now, build and create your own customized forms using Zoho Sheet. Be it compiling a questionnaire or rolling out a survey, Zoho Sheet can do it all for you. Forms is an excellent feature that helps you collect information in the simplest of ways and having it in Zoho Sheet takes it a notch higher. Build Simple yet Powerful forms Building forms using Zoho Sheet is fairly simple. The exclusive 'Form' tab lets you create one quickly. Whether you
      • Slicers are now available in Zoho Sheet—filter your data interactively

        At Zoho Sheet, we diligently track user requests and feedback. In line with this, based on extensive user requests, we've integrated Slicers to pivot tables and are delighted to announce its release. Slicers are interactive visual filters that have add,