Solved

Format Excell Cell date

Posted on 2014-02-05
3
378 Views
Last Modified: 2014-02-05
Hello,
can you please help,
I use a code to get information form SQL to Excel.
one of the lines in the code is
"WHERE((OrderDate >= '" & sh.[u1] & "')  And (OrderDate <='" & sh.[v1] & "')) "

if I format the cells like this, my Code works
Range("u1").Select
ActiveCell.FormulaR1C1 = "=TODAY()-1 + ""00:00:00"""
Range("u1").Select
ActiveCell.FormulaR1C1 = "=TODAY()-1 +""23:59:59"""


the issue I have is I need to be able to change the date in the cell.
so if I format the cells to below, my code will not work.

Range("u1").Select
Selection.NumberFormat = "[$-409]mm/dd/yyyy ""00:00:00"""
Range("u1").Select
Selection.NumberFormat = "[$-409]mm/dd/yyyy ""23:59:59"""

can you please help,
thanks
0
Comment
Question by:Wass_QA
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 300 total points
ID: 39836033
How about using the format function when pulling the date from excel?

"WHERE((OrderDate >= '" & Format(sh.[u1], "mm/dd/yyyy hh:mm:ss") & "')  And (OrderDate <='" & Format(sh.[v1], "mm/dd/yyyy hh:mm:ss") & "')) "

Matt
0
 

Author Comment

by:Wass_QA
ID: 39836801
thanks Matt,
this worked.

((OrderDate >= '" & format(sh.[u1], "mm/dd/yyyy 00:00:00") & "')  And (OrderDate <='" & format(sh.[v1], "mm/dd/yyyy 23:59:59") & "'))
0
 

Author Closing Comment

by:Wass_QA
ID: 39836804
Thank you.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now