Consulting

Results 1 to 2 of 2

Thread: Automatically Inserting Rows with Date, Each Worksheet

  1. #1
    VBAX Newbie
    Joined
    Mar 2014
    Posts
    4
    Location

    Automatically Inserting Rows with Date, Each Worksheet

    Hi folks. Some of you have already helped me with deleting rows upon opening a worksheet. Now I am asking for help again with inserting rows -- I promise this is the last time.

    Can someone help me with the VBA code to insert a row in the last row of my table, with today's date in Column B? Here's the catch - my workbook has multiple worksheets (tabs), each containing a single table. And, I need this action performed for every worksheet in the workbook, when the workbook is opened. On top of it all, I don't want the action repeated if the workbook is opened multiple times in the same day - only the first time it is opened.

    Thanks again in advance. You folks are great. I'm not sure why you choose to help total strangers with their tech problems, but I think it's fantastic.

    jaspr
    Attached Files Attached Files

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Private Sub Workbook_Open()
        Dim ws As Worksheet
        Dim lastrow As Long
        
        For Each ws In ThisWorkbook.Worksheets
        
            wsDeleteDateRows ws, 2, 6
            
            lastrow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
            If Application.CountIf(ws.Range("B6").Resize(lastrow - 5), Date) = 0 Then
            
                ws.Cells(lastrow + 1, "B").Value = Date
                ws.Cells(lastrow, "B").Copy
                ws.Cells(lastrow + 1, "B").PasteSpecial Paste:=xlPasteFormats
            End If
        Next ws
    End Sub
    ____________________________________________
    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

Posting Permissions

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