+ Reply to Thread
Results 1 to 3 of 3

Date in an Inputbox transferred to the specific cell of a worksheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Date in an Inputbox transferred to the specific cell of a worksheet

    Hi experts and gurus,

    I am at the end of the automated Report. I am looking to set up an input box that seeks the "Current Report Date" and "Last Report Date", which are then transferred to cells B1 and B2 of a worksheet respectively. The date will be in a specific format "DD/MM/YYYY".

    If the date is in invalid format, the message box will be prompted with "invalid date format".

    I have tried to write the following code which needs improvement to get the result.
    Private Sub A()
    
    Call reportingDate
    Worksheets("Test").Range("B1").Value = currep_date
    Worksheets("Test").Range("B2").Value = lastrep_date
    
    End Sub
    Function reportingDate()
    
    Dim currep_date As Date, lastrep_date As Date
    
       
        currep_date = InputBox("Enter Current Reporting Date", "Enter a Date")
        lastrep_date = InputBox("Enter Last Reporting Date", "Enter Date")
    
    End Function
    Can somebody help me to write a code to put a date that is transferred to B1 and B2?

    Thank you so much to all the experts and gurus to help me learn VBA.

    Roshan Shakya
    Last edited by Roshan.Shakya; 07-17-2019 at 03:24 PM. Reason: clarity

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Date in an Inputbox transferred to the specific cell of a worksheet

    Format the two cells to the format you like
    Private Sub A()
        Dim currep_Date as Date
        Dim LastRep_Date as DAte
        currep_Date =  reportingDate
        If currrep_Date = 0 Then Exit Sub
    
        LastRep_Date = reportingDate
        If LastRep_Date = 0 Then Exit Sub
    
    Worksheets("Test").Range("B1").Value = currep_date
    Worksheets("Test").Range("B2").Value = lastrep_date
    End Sub
    
    Function reportingDate() As Date
        Dim uiDate as String
        Do
            uiDate = InputBox("Enter Current Reporting Date", "Enter a Date")
            If uiDate = "False" Then Exit Function
            If Not IsDate(uiDate) then MsgBox "Please enter a date"
        Loop Until IsDate(uiDate)
        reportingDate = CDate(uiDate)
    End Function
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Date in an Inputbox transferred to the specific cell of a worksheet

    Hi milkerickson,

    I changed my code slightly as under:

    Private Sub A1001()
    
    Dim currep_Date As Date, lastrep_Date As Date
    
    currep_Date = Application.InputBox("Enter Current Reporting Date", "Enter a Date", "DD/MM/YYYY")
    lastrep_Date = Application.InputBox("Enter Last Reporting Date", "Enter Date", "DD/MM/YY")
    Worksheets("Test").Range("B1").Value = currep_Date
    Worksheets("Test").Range("B2").Value = lastrep_Date
    I tested your code and appreciate that it loops back to the user to put the date input but it does not capture the last reporting date. I would also like to know if we can set up an input box in such way that the user can move backward and forward to correct the input data?

    Thank you
    Roshan Shakya

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 8
    Last Post: 04-19-2018, 02:11 AM
  2. Replies: 3
    Last Post: 01-30-2018, 10:46 AM
  3. corruption transferred by every cell?
    By VerlindenG in forum Excel General
    Replies: 3
    Last Post: 09-07-2015, 09:01 AM
  4. [SOLVED] Userform Listbox selected data transferred to a Worksheet cell
    By Tony Hadj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-25-2014, 02:51 AM
  5. Adding to figures transferred from another worksheet
    By KMac362 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 09-05-2013, 01:37 PM
  6. Conditional Formatting for specific date in another Worksheet Cell
    By Pooger in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 04-24-2013, 07:48 AM
  7. info/data transferred/copied from worksheet to worksheet in same workbook!
    By joe dech in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-17-2012, 02:53 PM

Tags for this Thread

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