+ Reply to Thread
Results 1 to 8 of 8

Change Date when one of 4 fields = string

Hybrid View

  1. #1
    Registered User
    Join Date
    10-23-2020
    Location
    Kentucky
    MS-Off Ver
    2016
    Posts
    24

    Change Date when one of 4 fields = string

    so what im doing is setting a date with time in a cell. based on 4 other columns.
    Columns A are the options column b are what they mean.
    Column C is where time gets put
    Column D thru G are data validation fields where you can pick options from column A

    options fields
    A                      B                   C(Time)          D           E              F               G
    accept             Accept                 time          
    Refuse             Refuse                time
    Called accept    Accept                time
    called refuse     refuse                time
    no answer                               No time
    time off                                  no time
    im using Private Sub Worksheet_Change(ByVal Target As Range) to get this to update.

    Ex. lets say D and E = refuse and which is fine it gets time Now in C the way i want. but column F is time off it changes the time. i dont want this i want it to do nothing if B answers are blank[table="width: 500"]


    c
    Last edited by mthroesch; 11-08-2020 at 11:44 AM. Reason: Attaching File

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,050

    Re: Change Date when one of 4 fields = string

    There are instructions at the top of the page explaining how to attach your sample workbook.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Change Date when one of 4 fields = string

    As the lady said, please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation with manually calculated results, explaining which information is data and which is results, and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.

    It may be possible to do this with standard Excel functions with or without some helper columns.

    To upload a file click the Go Advanced button at the foot of your post, look underneath the post area for the Manage Attachments section and take it from there.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    10-23-2020
    Location
    Kentucky
    MS-Off Ver
    2016
    Posts
    24

    Re: Change Date when one of 4 fields = string

    here is the file hope it helps.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-23-2020
    Location
    Kentucky
    MS-Off Ver
    2016
    Posts
    24

    Re: Change Date when one of 4 fields = string

    I found a work around that seems to work any one see any issue with this .

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim LastRow As Long
        Dim WorkRng As Range
        Dim Rng As Range
        
        LastRow = Range("A" & Rows.Count).End(xlUp).Row
        
        ' Set the intersect ranges to look for changes
        Set WorkRng = Intersect(Application.ActiveSheet.Range("M7:M" & LastRow & ", O7:O" & LastRow & ", Q7:Q" & LastRow & ", S7:S" & LastRow), Target)
    
        If Not WorkRng Is Nothing Then ' Is the intersects not empty
            Application.EnableEvents = False
            For Each Rng In WorkRng
                If VBA.IsEmpty(Rng.Value) Then ' Check if cell has stuff in it if not use last date
                    Range("K" & Target.Row).Formula = "=IFERROR(IF(ISBLANK(INDEX(otadd($K$7:$K$" & LastRow & "),MATCH(B" & Target.Row & ",otadd($B$7:$B$" & LastRow & "),0)))," & Chr(34) & "Not Polled" & Chr(34) & ",INDEX(otadd($K$7:$K$" & LastRow & "),MATCH(B" & Target.Row & ",otadd($B$7:$B$" & LastRow & "),0)))," & Chr(34) & "Not Polled" & Chr(34) & ")"
                Else 'Update date and time
                    If Range("L" & Target.Row).Value >= "1" Or Range("N" & Target.Row).Value >= "1" Or Range("P" & Target.Row).Value >= "1" Or Range("R" & Target.Row).Value >= "1" Then
                        Range("K" & Target.Row).Value = Now
                    Else ' set date and time for last update
                        Range("K" & Target.Row).Formula = "=IFERROR(IF(ISBLANK(INDEX(otadd($K$7:$K$" & LastRow & "),MATCH(B" & Target.Row & ",otadd($B$7:$B$" & LastRow & "),0)))," & Chr(34) & "Not Polled" & Chr(34) & ",INDEX(otadd($K$7:$K$" & LastRow & "),MATCH(B" & Target.Row & ",otadd($B$7:$B$" & LastRow & "),0)))," & Chr(34) & "Not Polled" & Chr(34) & ")"
                    End If
                End If
            Next
            Application.EnableEvents = True
        End If
    End Sub

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Change Date when one of 4 fields = string

    Is it necessary to process a whole range of cells in M7:M..whatever i.e. the WorkRng range whenever a change is made to a single cell?

    Isn't this somewhat wasteful.? Surely you only need to operate with the row being changed,

    I don't fully understand what you need the OTADD function for nor why regular Excel functions won't work.

  7. #7
    Registered User
    Join Date
    10-23-2020
    Location
    Kentucky
    MS-Off Ver
    2016
    Posts
    24

    Re: Change Date when one of 4 fields = string

    I was using a regular formula to do this but i realized that when a update on the page happens it would change all cells with the Now or today function in the formula. while if i use this in VBA they do not update unless that row is updated. this is useful for me as the rolls are sorted by time and needs to be more they just date.

    Quote Originally Posted by Richard Buttrey View Post
    Is it necessary to process a whole range of cells in M7:M..whatever i.e. the WorkRng range whenever a change is made to a single cell?
    yes i think so. Columns M O Q S are for user input. and based on those column K gets update with date. or uses previous sheet date. and you moved M7 down to M lastcell then move to O then Q then S
    M could be blank so then O could be the control cell for K. ect..


    Isn't this somewhat wasteful.? Surely you only need to operate with the row being changed,
    im not sure if there is a way to do it with using less resources, Im more then happy to change but as of now I haven't found a better way.

    don't fully understand what you need the OTADD function for nor why regular Excel functions won't work.
    The OTADD function was me trying to shorten up formulas. it is for pulling the data from the previous sheet with out me having to know the previous sheets name ahead of time. this workbook is setup to make new sheets with all the required data from the current sheet, with formulas that will look at the previous sheet for data verification and restore data that was changed incorrectly. I was having issues with when the create new sheet was used it would create the sheet exactly as i wanted with the exceptions of not linking to correct previous sheet. the OTADD function fixed that issue. the name was for an entirely different use that worked better for this.

  8. #8
    Registered User
    Join Date
    10-23-2020
    Location
    Kentucky
    MS-Off Ver
    2016
    Posts
    24

    Re: Change Date when one of 4 fields = string

    there are some function / code in there from when i was creating a Results Sheet in stead of locking down the current sheet. i changed views on this when i realized this was creating un-needed sheets/resources being used. i also wanted to limit the number of conditional formatting and how many sheets i had to choose from. aka Sheet 1 gets copied to Results 1 then sorted. then Sheet 2 is created from Results 1. rinse and repeat.

    in the version i posted i removed all the protection code so that it didnt lock while yall were looking at it.
    Current method is Sheet 1 when done is sorted and finalized. finalizing removes all formulas and locks the sheet down. reducing the file size and resources needed. if editing is needed after words the sheet will reacquire all the needed formulas. Using the previous sheet data and pre-finalized data.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to change text dates into usable date fields
    By ammartino44 in forum Excel General
    Replies: 4
    Last Post: 09-06-2020, 08:42 PM
  2. Replies: 5
    Last Post: 07-23-2019, 07:18 AM
  3. Replies: 27
    Last Post: 03-29-2019, 10:47 PM
  4. Change written date (Day, day month time timezone) to date string
    By ABBOV in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-08-2017, 05:08 AM
  5. change a rows colour if the todays date is 1 month from the dates in the fields
    By andrewd94 in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 09-17-2013, 07:41 PM
  6. [SOLVED] Macro to deconstruct and change date string needed
    By Aceso in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2013, 12:41 PM
  7. [SOLVED] Excel SHOULD NOT AUTO-CHANGE formated text fields to DATE FIELDS!
    By PSSSD in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-08-2006, 04:35 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1