Consulting

Results 1 to 13 of 13

Thread: Solved: Change Event?

  1. #1
    VBAX Regular
    Joined
    Nov 2007
    Posts
    29
    Location

    Solved: Change Event?

    I have spent over four days trying to solve this. I am new to VBA, and this is frustrating.

    On an Excel sheet, A1=10, for example. This value is constantly changing.

    B1:B5 also contains constantly changing values.

    When A1 changes, I would like to sum B1:B5 with the resulting figure entered automatically into B7.

    Further, I would like to record B7 in a separate column, eg starting from C3.

    How is this to be done, step by step?

    Thank you in anticipation.

    Grant.
    Last edited by Grantx; 11-13-2007 at 03:31 PM.

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Grant,
    Not enough info....can you post an example file with some comments so we can see what you are trying to do.....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "A1" '<== change to suit

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target
    Me.Range("B7").Value = Application.Sum(Me.Range("B1:B5"))
    If Me.Range("C3").Value <> "" Then
    Me.Range("C" & Me.Rows.Count).End(xlUp).Offset(1, 0).Value = Me.Range("B7").Value
    Else
    Me.Range("C3").Value = Me.Range("B7").Value
    End If
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/vba]

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular
    Joined
    Nov 2007
    Posts
    29
    Location
    Steve,

    As requested, please see attachment.

    Xld,

    I've just noticed your reply while entering this in the "Reply to Thread" box. Will reply in due course.

    Grant.

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    That's nice Bob. I couldn't wrap my head around what he was trying to do.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Regular
    Joined
    Nov 2007
    Posts
    29
    Location

    SOLVED

    Xld,

    Thank you for the solution; entered as suggested (it can't be tested until tomorrow am GMT).

    Grant.

  7. #7
    VBAX Regular
    Joined
    Nov 2007
    Posts
    29
    Location
    Copied and entered as directed but nothing happening. Suggestions?

    Grant.

  8. #8
    Did you adjust the range as Bob indicated ?
    2+2=9 ... (My Arithmetic Is Mental)

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That's odd, because I opened your spreadsheet, poked the code in without any changes, removed your comments, and it worked perfectly.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Grant,
    did you follow Bob's instructions in post #3 and put the code in the module for the sheet?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  11. #11
    VBAX Regular
    Joined
    Nov 2007
    Posts
    29
    Location
    Gentleman,

    I opened the sheet (zip file above) and re-copied Xld's code from above. It worked.

    Thank you, Xld.

    I have other questions which will be posted under new headings. Maybe I'll see you there.

    Grant.

  12. #12
    So what was the problem ?
    2+2=9 ... (My Arithmetic Is Mental)

  13. #13
    VBAX Regular
    Joined
    Nov 2007
    Posts
    29
    Location
    XLD,

    Please refer to the attachment.

    Sum (B7) stopped working and populating the column C ended. However, A1
    and B1:B5 were constantly changing. Can this be rectified?

    (Is it possible to "cut and paste" code/text in the Message box?)

    Thank you for your help.

Posting Permissions

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