VBA advance date by one day

scottleger4

New Member
Joined
Oct 3, 2016
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Good morning! I'm trying to create a loop that operates with a specified date range and interacts with host explorer. I need it to advance the start date by one until it goes past the end date and then stop. Here was my first go at it, but stepping through eventually led to a "Run-time error '13': Type mismatch" at my "a = a + 1".

a = SDate
b = EDate
OnRent = OnRent1
Do Until a > b
Wait
RC = MyHost.keys(OnRent)
RC = MyHost.runcmd("TAB")
a = a + 1
Set OnRent = OnRent.Offset(0, 1)
Wait
WaitForReady
Loop

If SDate = 10/18/2018 (for example), how do I tell VBA to change SDate to be 10/19/2018 after running the two "RC" lines of code? Thanks in advance.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
.
I don't understand the use of :

RC = MyHost.keys(OnRent)
RC = MyHost.runcmd("TAB"

But, it seems like you are checking the current date against a Due Date for rent payment ?
If so, here is a method I use to check dates. Hopefully, you can use it in your project :


Code:
Option Explicit


Sub IsOvrDue()
Dim i As Long
    
    For i = 2 To 50
        If Cells(i, 11).Value = "" Then         '11 is Col K
            Cells(i, 4).Value = ""              '4 is Col D
        ElseIf Cells(i, 11).Value < Now() Then  'If the date in Col K row is older than today, it is overdue
            Cells(i, 4).Value = "Overdue"       'Write Overdue in Col D
        End If
    Next
    
End Sub
 
Upvote 0
What is SDate? A number? A string?
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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