+ Reply to Thread
Results 1 to 9 of 9

Multiple iteration of a date stamp

Hybrid View

  1. #1
    Registered User
    Join Date
    05-15-2013
    Location
    Stoke on Trent
    MS-Off Ver
    Excel 2003
    Posts
    2

    Multiple iteration of a date stamp

    Hi

    Can comeone please help? I have the below code to date stamp a cell in column AN only when a cell in column AB equals 0...the trouble is I would like this to work for the entire column without having to keep copy and pasting the code like I have below.

    Also if there is any other number in column AB i want it to skip that row, not date stamp in column AB but move to the next row down?? Lastly, once the date stamp is in the relevant cell in column AN I never want it to overtype,

    Any help would be greatly appreciated


    I am currently using:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Sheets("Performance Board").Unprotect "password"
    
    If Intersect(Target, Range("AB8")) = 0 Then
    If Range("AN8").Value <> "" Then Exit Sub
    Application.EnableEvents = False
        Range("AN8").Value = Now
        Range("AN8").NumberFormat = "d dddd yyyy  hh:mm:ss"
    Application.EnableEvents = True
    End If
    
    If Intersect(Target, Range("AB9")) = 0 Then
    If Range("AN9").Value <> "" Then Exit Sub
    Application.EnableEvents = False
        Range("AN9").Value = Now
        Range("AN9").NumberFormat = "d dddd yyyy  hh:mm:ss"
    Application.EnableEvents = True
    End If
    
    If Intersect(Target, Range("AB10")) = 0 Then
    If Range("AN10").Value <> "" Then Exit Sub
    Application.EnableEvents = False
        Range("AN10").Value = Now
        Range("AN10").NumberFormat = "d dddd yyyy  hh:mm:ss"
    Application.EnableEvents = True
    End If
    
    Sheets("Performance Board").Protect "password"
    
    End Sub
    Last edited by Leith Ross; 05-16-2013 at 01:43 PM. Reason: Added Code Tags

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Multiple iteration of a date stamp

    if target.column = target.worksheet.range("AN1").column then
    
    end if
    Last edited by Leith Ross; 05-16-2013 at 01:44 PM. Reason: Added Code Tags

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Multiple iteration of a date stamp

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Const cstColumnsApart = 12
    Const cstANColumn = 40
    
    If Target.Offset(0, (0 - cstColumnsApart)).Value = 0 Then
        Cells(Target.Row, cstANColumn).Value = Format(Now, "d dddd yyyy hh:mm:ss")
    End If
    
    End Sub
    Last edited by Leith Ross; 05-16-2013 at 01:43 PM. Reason: Added Code Tags

  4. #4
    Registered User
    Join Date
    05-15-2013
    Location
    Stoke on Trent
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Multiple iteration of a date stamp

    Thanks for your help but this doesn't work, the code we have works but we need it to just continue down the entire row of cells. We think this is 'Do Unitl' but are fairly new at VBA...the code is:
    If Intersect(Target, Range("AB8")) = 0 Then
    If Range("AN8").Value <> "" Then Exit Sub
    Application.EnableEvents = False
        Range("AN8").Value = Now
        Range("AN8").NumberFormat = "d dddd yyyy  hh:mm:ss"
    Application.EnableEvents = True
    End If
    We essentially want this to repeat in row AB until it reaches the last row??

    Many thanks again
    Last edited by Leith Ross; 05-16-2013 at 01:44 PM. Reason: Added Code Tags

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Multiple iteration of a date stamp

    it would be something like

    for I = 1 to activesheet.usedrange.rows.count
    Last edited by Leith Ross; 05-16-2013 at 01:45 PM. Reason: Added Code Tags

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Multiple iteration of a date stamp

    it would be something like

     for I = 1 to activesheet.usedrange.rows.count 
         if activesheet.range("AB" & I).value <>"" then
             Range("AN").Value = Now
             Range("AN").NumberFormat = "d dddd yyyy hh:mm:ss"
         end if
    next I

  7. #7
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Multiple iteration of a date stamp

    sorry, wrong idea

  8. #8
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Multiple iteration of a date stamp

    I got you now, I thought you wanted it to only check the row you'd changed

  9. #9
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Multiple iteration of a date stamp

    Range("AN" & I).Value = Now
    SORRRRRRY
    Last edited by Leith Ross; 05-16-2013 at 01:44 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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