Populating fields based on action

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
Hello,

I am trying to create a "DateAdded" field to my spreadsheet. What I would like to be able to happen is that once values are populated in columns A,B,C,D,E and H of a row to have the current date/time in Column BV


Is this possible? I am suspecting that it would involve VBA but not sure. I have experience with VBA in Access, but not excel.
 
Ok. Thank you. I work primarily in Access when doing VBA so this has been a learning experience.

I am playing with two solutions to my problem and this is looking like a viable solution.
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I am playing with two solutions to my problem and this is looking like a viable solution.
What is the other solution you are playing around with?
 
Upvote 0
It is an access based solution. that records a "created" date when we do more of the processing as the Excel spreadsheet gets migrated to Access for other processing.
 
Upvote 0
So fellow MVP Rick Rothstein showed me how to avoid doing the unnecessary extra loop. Just one minor change (highlighted in red):
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng1 As Range
    Dim rng2 As Range
    Dim rng3 As Range
    Dim isect As Range
    Dim r As Range
    Dim myRow As Long

'   Set columns to look in
    Set rng1 = Application.Union(Range("A:E"), Range("H:H"))
    
'   Check to see what cells being updated insersect with myRange
    Set isect = Intersect(Target, rng1)
    
'   Exit if no cells being updated fall in range
    If isect Is Nothing Then Exit Sub

    Application.ScreenUpdating = False
    
'   Loop through all rows in intersted range
    For Each r In isect[COLOR=#ff0000].Areas(1)[/COLOR].Rows
        myRow = r.Row
        Set rng2 = Range("A" & myRow & ":E" & myRow)
        Set rng3 = Range("H" & myRow)
        If WorksheetFunction.CountBlank(rng2) + WorksheetFunction.CountBlank(rng3) = 0 Then
            If Cells(myRow, "BV") = "" Then Cells(myRow, "BV") = Now
        End If
    Next r

    Application.ScreenUpdating = True
    
End Sub
So this should be more efficient, and run a little faster.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top