Worksheet change code to work from VB-VBForums
Results 1 to 3 of 3

Thread: Worksheet change code to work from VB

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2007
    Posts
    132

    Worksheet change code to work from VB

    I am using the following code in excel to perform a job:
    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 3 And Target.Row = 2 Then
    ' do this
    End Sub
    How can I use this type of codes ie not related to Excel VBA module from
    VB6?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,591

    Re: Worksheet change code to work from VB

    why would you change it? it will still work if the workbook is opened from vb6
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2007
    Posts
    132

    Re: Worksheet change code to work from VB

    Thanks for the reply.
    I want to put the code in VB6 and not in the excel file The full code is like this
    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 3 And Target.Row = 2 Then
    Sheets("Statement").Rows.Hidden = False  ' This is new line to unhide earlier rows
    For i = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
    If (Cells(i, 3) = 0 And IsEmpty(Cells(i, 3)) = False) Or _
    (Cells(i, 4) = 0 And IsEmpty(Cells(i, 4)) = False) Or _
    (Cells(i, 5) = 0 And IsEmpty(Cells(i, 5)) = False) Then
    Cells(i, 1).EntireRow.Hidden = True
    End If
    Next
    End If
    End Sub
    I want to trigger this code from VB6 and doesnot want to keep in the excel file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.