Consulting

Results 1 to 4 of 4

Thread: From a form - write todays date and a variable value in the next available row

  1. #1

    From a form - write todays date and a variable value in the next available row

    My ultimate goal: from my form - Take today's date and put it in the next available cell in column A and the value of the variable "Howmany" next to it in column B

    OMG this should be so simple but I can't get it to write on the proper worksheet. Here is my code for writing the variable. (figured I could do "offset" and "DATE" somehow for the date part.)

    This gets runtime error 1004 no cells found:

    Dim r As Range
    Sheets("Numbers").Activate
    Set r = Intersect(ActiveSheet.UsedRange, Range("A:A")).Cells.SpecialCells(xlCellTypeBlanks)
    r(1) = Howmany
    (yada yada ... put date in column A somehow)

  2. #2
    it worked as coded (the passing the variable part) but it wrote in the active sheet at the time. I want to make the sheet "Numbers" active and write it in there instead

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Something simple maybe?

    Usually there's no need to select or activate a sheet just to get or put data

    Option Explicit
    Sub test()
        Dim howmany As Long, nextrow As Long
        
        howmany = 12345
        
        nextrow = Worksheets("Numbers").Cells(Worksheets("Numbers").Rows.Count, 1).End(xlUp).Row + 1
        Worksheets("Numbers").Cells(nextrow, 1).Value = Date
        Worksheets("Numbers").Cells(nextrow, 2).Value = howmany
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    OMG that's perfect. Thanks for the quick response.

Posting Permissions

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