+ Reply to Thread
Results 1 to 4 of 4

Adding a row on Open

  1. #1
    Registered User
    Join Date
    06-20-2006
    Posts
    39

    Adding a row on Open

    Hi everyone,

    This might seem trivial to many but I don't seem to understand it why I am having trouble with this. I have the following code

    Please Login or Register  to view this content.
    As you can see, I want to compare a cell with today's date. If it's not today's date, then add a new row (since data will be added). The code looks correct to me, but I don't doubt something is wrong since it obviously is not working properly. Everytime I open the workbook, it adds a new row regardless whether cell A4 has today's date or not. Does anyone have any insight as to what may be going on?

    Thanks in advance.

    -- Isaac

  2. #2
    Registered User
    Join Date
    06-20-2006
    Posts
    39
    Sorry. Clearly, there is only one "Private Sub Workbook_Open()" in the code. Ignore one of them (since it is not in my code).

    -- Isaac

  3. #3
    Gary Brown
    Guest

    RE: Adding a row on Open

    The code worked fine for me.

    2 suggestions however...
    1) change Today to strToday
    - this puts you in the habit of using traditional nomenclature for
    variables
    - this stops issues that can arise from using the same name as a funtion
    Today()
    2) put a '.' in front of your code
    > Rows("4:4").Insert Shift:=xlDown

    so that if you are on another worksheet, the row will only be inserted on
    worksheet(4)
    ie: .Rows("4:4").Insert Shift:=xlDown

    Sorry I couldn't help more.
    Have you tried stepping through the code to see where something might be
    going wrong?

    Sincerely,
    --
    Gary Brown
    [email protected]
    If this post was helpful to you, please select 'YES' at the bottom of the
    post.



    "I Maycotte" wrote:

    >
    > Hi everyone,
    >
    > This might seem trivial to many but I don't seem to understand it why I
    > am having trouble with this. I have the following code
    >
    >
    > Code:
    > --------------------
    > Private Sub Workbook_Open()
    > Private Sub Workbook_Open()
    > Dim Today As String
    > Today = "=Today()"
    >
    > With Worksheets(4)
    > If .Cells(4, 1).Value <> Today Then
    > Rows("4:4").Insert Shift:=xlDown
    > .Cells(4, 1) = Today
    > End If
    > End With
    > End Sub
    >
    > --------------------
    >
    >
    > As you can see, I want to compare a cell with today's date. If it's
    > not today's date, then add a new row (since data will be added). The
    > code looks correct to me, but I don't doubt something is wrong since it
    > obviously is not working properly. Everytime I open the workbook, it
    > adds a new row regardless whether cell A4 has today's date or not.
    > Does anyone have any insight as to what may be going on?
    >
    > Thanks in advance.
    >
    > -- Isaac
    >
    >
    > --
    > I Maycotte
    > ------------------------------------------------------------------------
    > I Maycotte's Profile: http://www.excelforum.com/member.php...o&userid=35604
    > View this thread: http://www.excelforum.com/showthread...hreadid=557836
    >
    >


  4. #4
    Registered User
    Join Date
    06-20-2006
    Posts
    39
    Thanks a lot Gary! The issue was resolved as soon as I put the '.' in front of my code.

    -- Isaac

+ 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