Working with dates within VBA not cells

krice1974

Active Member
Joined
Jul 3, 2008
Messages
422
Hi all. I'm trying to write a macro that loops, with each pass rewriting a web query address string that uses a date. The query returns a table with one days' data. When each date's table is returned, I'll extract the data out of it, delete the query, and rewrite the string incrementing by one day, repeating 30 times.

The string needs the date in this format: March 13, 2009 is 20090313.

My problem is how to use the useful date worksheet functions within VBA and not having to calculate each next date in a cell.

Any takers? This seems like a fun bit of code...
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
DateOfInterest = DateSerial(2009,3,13)
DateString = Format(DateOfInterest,"mmmm dd, yyyy")

Hope that helps...
 
Upvote 0
Date function in vba?

Have you tryed DateValue or DateSerial function ?

e.g

Format(DateSerial(2009,3,13),"yyyymmdd")
 
Upvote 0
I'm not sure how that would determine the next day though, then extract the values within it as integers or strings... flipping to the next month when adding day +1 to the last day of a month etc...
 
Upvote 0
so the problem isn't really how to format the date, but how to obtain the date...

What do you mean by the next day?

What is the beginning date? How do you get the beginning date, what date do you want?
 
Upvote 0
try
Code:
Dim StartDate As Date, EndDate As Date, i As Long
StartDate = Date
EndDate = DateValue("2009/4/10")
For i = 0 To EndDate - StartDate + 1
    MsgBox Format(StartDate + i, "yyyymmdd")
Next
 
Upvote 0
Hi Jonmo, I didn't see your first post.

OK. I want to run it every day, starting with tomorrow of each day that it runs, looping for 30 days, so a for-next loop with NextDay (variable) being incremented by 1. So if it ran today, it'd start by returning 20090313 as the first assignment to NextDay. Hope that's clearer...
 
Upvote 0

Forum statistics

Threads
1,214,389
Messages
6,119,232
Members
448,879
Latest member
VanGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top