+ Reply to Thread
Results 1 to 14 of 14

Basic question about inserting a date into a formila

  1. #1
    Registered User
    Join Date
    04-16-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    21

    Basic question about inserting a date into a formila

    I know this is a pretty basic question but I'm new to excel so any help would be appreciated. I am creating a macro that will take the place of a repetitive sequence that I have been doing manually (the purpose of most macros, right?). At one point I am adding the following formula into a cell:

    =ROWS(B2:B145)&" Badges received January 25, 2013"

    I have been entering the date manually thus far but would prefer the macro to use a formula to enter the date. Ideally it would be the date of the next day after the macro was run, but the date the macro was run would work.

    Alternatively, if the macro could stop and wait for me to input the information and then continue to run I could continue to type the date manually and then instruct the macro to continue.

    Any suggestions?

    Thanks,
    David

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Basic question about inserting a date into a formila

    Try

    =ROWS(B2:B145)&" Badges received " & Format(Date+1,"mmmm dd, yyyy")

  3. #3
    Registered User
    Join Date
    04-16-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Basic question about inserting a date into a formila

    That's gets me an error message. I've attached a sample to demonstrate. Am I doing something wrong?

    David
    Attached Files Attached Files

  4. #4
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Basic question about inserting a date into a formila

    Well, you said you were creating a Macro to put the formula in the cell, so I used VBA Terms (format and date)
    So it would be like

    Range("A1").Formula = "=ROWS(B2:B145)&" Badges received " & Format(Date+1,"mmmm dd, yyyy")"

    But to enter it directly into a cell by hand it would be
    =ROWS(B2:B145)&" Badges received " &TEXT(TODAY()+1,"mmmm dd, yyyy")

    In VBA it's Format and Date
    In formula it's Text and TODAY()

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Basic question about inserting a date into a formila

    ROWS(B2:B145) can't see what that does it just =144 wherever you put it
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  6. #6
    Registered User
    Join Date
    04-16-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Basic question about inserting a date into a formila

    Quote Originally Posted by martindwilson View Post
    ROWS(B2:B145) can't see what that does it just =144 wherever you put it
    That part of the formula was used by clicking in B2 and then pressing end and then Shift-↓. Cell B145 was the last cell in that column to have data.

    I forgot to use Relative References, didn't I?
    Last edited by DWG3; 04-25-2013 at 02:16 PM.

  7. #7
    Registered User
    Join Date
    04-16-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Basic question about inserting a date into a formila

    Quote Originally Posted by Jonmo1 View Post
    Try

    =ROWS(B2:B145)&" Badges received " & Format(Date+1,"mmmm dd, yyyy")
    I'm still getting an error message when I run tht in a macro. I've attached another sample. Thanks for all your help!
    Attached Files Attached Files

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Basic question about inserting a date into a formila

    let's step back a minute....Ignore VBA for now..

    What do you want the formula to look like once it's in the cell ?
    Furthermore, do you really actually want the 'Formula' in the cell? or do you just want the 'result' of the formula in the cell?

    A good practice for devloping VBA is to first know what you want the result to be, and work back from there.
    Last edited by Jonmo1; 04-25-2013 at 02:29 PM.

  9. #9
    Registered User
    Join Date
    04-16-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Basic question about inserting a date into a formila

    The formula you gave me to run NOT in a macro worked. I want the cell contents to show the number of cells in column B that contain data and then the text "Badges received" and then show the date for the day after the information is entered.

    Does that make sense?

  10. #10
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Basic question about inserting a date into a formila

    So this is how you want the formula to look in the cell
    =ROWS(B2:B145)&" Badges received " &TEXT(TODAY()+1,"mmmm dd, yyyy")

    Then
    ActiveCell.Formula = "=ROWS(B2:B145)&"" Badges received "" &TEXT(TODAY()+1,""mmmm dd, yyyy"")"

  11. #11
    Registered User
    Join Date
    04-16-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Basic question about inserting a date into a formila

    That worked, you guys are great. How can I change the range from a fixed B2:B145 to B2:last cell in column B with data?

  12. #12
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Basic question about inserting a date into a formila

    How about

    ActiveCell.Formula = "=COUNTA(B:B)-1&"" Badges received "" &TEXT(TODAY()+1,""mmmm dd, yyyy"")"

    The -1 is assuming B1 is NOT blank.

  13. #13
    Registered User
    Join Date
    04-16-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Basic question about inserting a date into a formila

    Perfect, thanks again!

  14. #14
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Basic question about inserting a date into a formila

    Glad to help, thanks for the feedback.

+ 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