Solved

Excel Macro calling VB code ActiveCell.Formula issue with date

Posted on 2013-11-13
2
337 Views
Last Modified: 2013-11-14
I have a hotkey setup to call a Macro that is VB code.

I get the input box and after entering a date the cells update with #name value instead of doing the date calculation.

I've tried this:

    Dim agedate As String
    agedate = InputBox("enter age from date mm/dd/yyyy", "Data Entry")
    result = CDate(agedate)
    Dim adate As Date
    adate = DateValue(agedate)
    ActiveCell.FormulaR1C1 = "=DAYS360([@[Disch Date]]," & adate & ")"


And this:

    Dim AgeDate As Date
    AgeDate = InputBox("Enter date of ATB mm/dd/yyyy", "Data Entry")
    ActiveCell.FormulaR1C1 = "=DAYS360([@[Disch Date]],AgeDate)"


Any help would be appreciated.

Regards,
Torrey
0
Comment
Question by:Torrey Bates
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39647041
Torrey,
Assuming that you are using m/d/yyyy short date format, you can use:
    Dim agedate As String
    agedate = InputBox("enter age from date mm/dd/yyyy", "Data Entry")
    ActiveCell.FormulaR1C1 = "=DAYS360([@[Disch Date]],""" & agedate & """)"

Open in new window

Brad
0
 
LVL 2

Author Closing Comment

by:Torrey Bates
ID: 39648977
Thanks!
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question