Gowri A

Gowri A

  • NA
  • 54
  • 46.7k

how to add worksheet change event to excel from c#

Sep 9 2014 10:09 AM
How to add the following excel vba sheetchange event to c#



Private Sub Worksheet_Change(ByVal 

Target As Range)
If Not Intersect(Target, Range("A1", 

"A101")) Is Nothing Then
        Dim CellAddress, address, 

position, formula1 As String
        CellAddress = Target.address
            If Range(CellAddress).Value 

<> "" Then
            address = CellAddress
            position = Mid(address, 4, 

3)
                Range("B" & 

position).Select
                Range("B" & 

position).Clear
                With 

Selection.Validation
                    .Delete
                     .Add 

Type:=xlValidateList, 

AlertStyle:=xlValidAlertStop, 

Operator:= _
        xlBetween, 

formula1:="=indirect(A" & position & 

")"
                    .IgnoreBlank = True
                    .InCellDropdown = 

True
                    .InputTitle = ""
                    .ErrorTitle = ""
                    .InputMessage = ""
                    .ErrorMessage = ""
                    .ShowInput = True
                    .ShowError = True
                End With
            End If
    End If
End Sub