Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

How to track change in cell and still can use previous data

0

Hi,

i have no knowledge in VBA. I have read some tutorials in how to create cell changes tracker. But can't find how to display those changes (or no need to display them, as it will be too many) and still can do some calculation on those already-been-changed data in that cell.

For example: people can sign up his/her name in a cell. As long as he/she put his/her name in the cell, it will be taken to calculate the booking fee (5$). Even if the person will later cancel it, he/she will still have to pay for the 5$. And if the second person fills his/her name in the same cell after the first person cancels, he/she will also have to pay the 5$. And so on for the next person, if any. 

So, if any way to do that? 

i upload my sample excel file. 

thanks in advance for any help. 

kt

Answer
Discuss

Discussion

Hi Xxtran and welcome to the Forum.

Seems to me that you just need to record additions and changes to column   of your worksheet "Oct" and to uplift the value in column F of "Booking Fees" for that player (even if the same court/time is booked several times). I've created a file that does that and recorded a lists of timed bookings but don't have time to explain it in an Answer. Sound like it might work for you?
John_Ru (rep: 6142) Oct 19, '23 at 10:40 am
Or are you hoping to track several changes (e.g. to create a new or revised booking) and undo them if that booking is not made? One appraoch to that would be to create a booking using a VBA "Userform" and commit the booking detailed in that to the spreadsheet only once it is confrimed by the person booking the game.
John_Ru (rep: 6142) Oct 20, '23 at 8:26 am
Hi John,
i don't see your file ....
i actually want to track several changes (if any). For example, if Sheet Oct cell B215 is Man, then sheet BookingFees cell F2 should count 1, even if the player Man later would decide to cancel et remove his name, BookingFees cell F2 should have stayed with 1 (and not coming back to zero). And if sheet Oct cell B215 will have another player name, corresponding cell in BookingFees should count 1 (and if again the second name on that cell removed, the counting stay 1 and not coming back to zero. And so on.
thanks a lot
xttran Oct 21, '23 at 2:44 am
Hello xxtran,

I too have been working on a solution for you. I would like you to answer the following questions so my solution can be as complete as possible.
Are standby postions (1, 2, & 3) charged a booking fee?
Does the actual file have 12 monthly sheets? Or does it only have "Oct"?
Will everyone have access to the "Oct" sheet? If so, how do you plan on preventing "David" from deleting/changing bookings made by "Allen" etc.?
Who enters the "Booking Name"?
Will everyone have access to the "BookingFees" sheet?
These are the only questions I have for now.

Cheers   :-)
WillieD24 (rep: 557) Oct 25, '23 at 5:26 pm
Add to Discussion

Answers

0

Xxtran

I didn't notice your note in the file so this Answer may not be right but take a look any way please...

In the attached revised file, I assumed that the Booking Name pays $5 (but I think it should be Player though I didn't see an example). It needs to be opened with macros-enabled (please search the internet to see how with your version of Excel).

In the sheet "Oct", create a court booking (say row 217) but leave column F (Booking Name) to the last. Then choose a Booking name from the drop-down (e.g in F217). Once you do that this macro will run (commented for your understanding):

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim Cl As Range, Lieu As String, LDate As String
    Dim BkText As String, r As VbMsgBoxResult, LstRw As Long, n As Long
    ' do nothing unless acell in F is changed
    If Intersect(Target, Columns(6)) Is Nothing Then Exit Sub

    ' for any cells chnaged in F (e.g. via paste), loop though...
    For Each Cl In Intersect(Target, Columns(6)).Cells
        ' skip if the timeslot in A is blank
        If Cl.Value <> "" Then
            ' otherise, record the start time
            LSession = Format(CDate(Cells(Target.Row, 1).Value), "hh:mm")
            ' got up the sheet from there but in column A
            For n = Cl.Row To 2 Step -1
                ' if the cell is read, record the value as the game start time
                If Cells(n, 1).Font.Color = 255 Then
                    LDate = Format(Cells(n, 1).Value, "yyyy-mm-dd")
                    ' and jump out of loop to save venue (from line below, last time)
                    Exit For
                 End If
                 ' if i's not a time, record it as the venue
                 If IsNumeric(Cells(n, 1).Value) = False Then Lieu = Cells(n, 1).Value
            Next n
            ' collect the booking details, as recorded
            BkText = Now & " " & Cl.Value & " booked " & Lieu & " " & LSession & " on " & LDate
            ' show details and tell the user to confirm or not
            r = MsgBox(BkText, vbYesNo, "Proceed with this booking?")
            If r = vbYes Then
                ' if yes, find last used row in Booking Fees...
              LstRw = Worksheets("Booking Fees").Range("A" & Rows.Count).End(xlUp).Row
              For n = 2 To LstRw
                ' loop down to match name
                If Worksheets("Booking Fees").Cells(n, 1) = Cl.Value Then
                ' if found, increase column F by 1 (causes $5 charge) then exit loop
                    Worksheets("Booking Fees").Cells(n, 6) = Worksheets("Booking Fees").Cells(n, 6) + 1
                    Exit For
                End If
              Next n
              ' if name was found...
              If n <= LstRw Then
                ' add bboking data after last row on that sheet
                LstRw = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
                Sheet1.Range("A" & LstRw + 1) = BkText
                Else
                ' if not, tell user (and don't chnage sheets ### NEED to undo
                MsgBox "Error- booking name " & Cl.Value & " not found. Either add name to Booking Fees sheet and try again OR undo changes"
              End If
            End If
        End If
    ' loop back for next (if any)
    Next Cl

End Sub

It will show a VBA Message Box with a summary showing current time and the booking e.g. "24/10/2023 09:17:07 Jingxin booked McClerry 12:15 on 2023-10-01". If you click "Yes", it will add 1 to column F (Playing frequency) on sheet "Booking Fees" so Jingxin is charged $5. It also records that booking on the last row of new sheet "Booking records" (so you can justify why a player owes an amount, should they question it).

Click "No" instead and that doesn't happen (but I didn't create an Undo)

If you change the same booking to another Booking Name, another fee is charged.

If you paste several entries for Booking Name (perhaps unlikely), it shows each one as detailed above.

Hope this gives you an insight into the power of VBA. Please comment and if I get time I'll correct the file.

Discuss

Discussion

@John,

Since Xxtran hasn't commented on your solution, nor provided the additional info I asked for, I am no longer working on an alternate solution.
WillieD24 (rep: 557) Oct 29, '23 at 11:31 am
@Willie - Wise move! Don't waste your time on a non-responsive user. 
John_Ru (rep: 6142) Oct 29, '23 at 4:33 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login