Do Until Loop

nniedzielski

Well-known Member
Joined
Jan 8, 2016
Messages
598
Office Version
  1. 2019
Platform
  1. Windows
I am running a macro that is going back 15 days scraping data, I need to know how to write code that will get my macro to stop after it has gone back 15 days, I was thinking of dooing a Do Until Loop, but i cant figure out how to write a Do Until that will stop after 15 days.

Here is what I have so far:

Code:
9
    lDate = lDate - 1
    lMonth = Format(lDate, "mm")
    lDay = Format(lDate, "dd")
    lYear = Format(lDate, "yy")
    lweekday = Weekday(lDate, vbMonday)
    GoTo 64

I only want this to be done for 15 days and then stop going to 64.

How can I achieve this?

thank you,
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How about
Code:
Dim i As Long
For i = 1 To 15
   lDate = lDate - 1
   lMonth = format(lDate, "mm")
   lDay = format(lDate, "dd")
   lYear = format(lDate, "yy")
   lweekday = Weekday(lDate, vbMonday)
   ' do whatever
Next i
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,517
Messages
6,125,288
Members
449,218
Latest member
Excel Master

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