+ Reply to Thread
Results 1 to 5 of 5

Use data from input box into a formula and show result in active cell

Hybrid View

  1. #1
    Registered User
    Join Date
    12-21-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    21

    Use data from input box into a formula and show result in active cell

    Hi All

    i was trying to write a macro so that user can get a input box and select any cell with date and hit OK then macro use that date in a formula and present the result in active cell. below is the code i tried, but it is giving error: #NAME?

    Sub getweeknumber()
    Dim originaldate As Date

    originaldate = CDate(Application.InputBox("select the source", "Get Week Number"))
    ActiveCell.Value = "=weeknum(originaldate,1)"

    End Sub

    any help will be much appreciated.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,966

    Re: Use data from input box into a formula and show result in active cell

    Option Explicit
    Sub getweeknumber()
        Dim originaldate As Range
        
        Set originaldate = Application.InputBox("select the source", "Get Week Number", Type:=8)
        ActiveCell.Formula = "=weeknum(" & originaldate.Address(0, 0) & ",1)"
        
    End Sub
    Ben Van Johnson

  3. #3
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Use data from input box into a formula and show result in active cell

    What are you trying to:

    a. Put the weeknum formula into the active cell, or

    b. Put the result of the weeknum formula into the active cell?

    If A then:

    ActiveCell.Formula = "=weeknum(" & CDbl(originaldate) & ",1)"
    If B then:

    ActiceCell.Value = WorksheetFunction.WeekNum(originaldate, 1)

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Use data from input box into a formula and show result in active cell

    Hmmm, I should have read your original post better, really.

  5. #5
    Registered User
    Join Date
    12-21-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Use data from input box into a formula and show result in active cell

    many thanks guys. it worked

+ 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