loop not changing values

smakatura

Board Regular
Joined
May 27, 2011
Messages
141
I want to look at a list of dated files and open them in order. below is my code.

HTML:
Dim loopcounter As Integer
Dim rptdate As Date
Dim datafilename As String
Dim datafilelocation As String
Dim fulldatafilename As String
Dim fulldatafilelocation As String
 
   rptdate = Application.InputBox("Enter date.", Title:="Date Entry", Type:=1)
 
    sourcedocument = "JOBS Weekly Template.xlsm"
    datafilelocation = "C:\Users\smakatura\Documents\current project\jackie report\call logs1\"
    datafilename = "JOBS Center Call Log Master "
    fulldatafilename = datafilename & Format(rptdate, "mm-dd-yy") & ".xlsx"
    fulldatafilelocation = datafilelocation & fulldatafilename
 
 
DO
     Workbooks.Open Filename:=fulldatafilelocation
     loopcounter = loopcounter + 1
     rptdate = rptdate + 1
     MsgBox (rptdate)
Loop Until loopcounter = 3

before the loop: the rptdate is 09-26-11(entered value into input box)
first loop: opens the file with the date 09-26-11 and says message box says rptdate is 9-27-11
second loop: file with date 09-26-11 opens instead of 09-27-11 and msgbox says that rpt date is now 9-28-11

basically msgbox is saying correct 'new rptdate' but the file opening is stil the first rptdate...not the the updated rptdate.
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You are not redefining the fine names in each loop run. Try this change:

Code:
Dim loopcounter As Integer
Dim rptdate As Date
Dim datafilename As String
Dim datafilelocation As String
Dim fulldatafilename As String
Dim fulldatafilelocation As String
 
   rptdate = Application.InputBox("Enter date.", Title:="Date Entry", Type:=1)
 
    sourcedocument = "JOBS Weekly Template.xlsm"
    datafilelocation = "C:\Users\smakatura\Documents\current project\jackie report\call logs1\"
    datafilename = "JOBS Center Call Log Master "

 
 
DO
     fulldatafilename = datafilename & Format(rptdate, "mm-dd-yy") & ".xlsx"
     fulldatafilelocation = datafilelocation & fulldatafilename
     Workbooks.Open Filename:=fulldatafilelocation
     loopcounter = loopcounter + 1
     rptdate = rptdate + 1

     MsgBox (rptdate)
Loop Until loopcounter = 3
 
Upvote 0
that worked perfiectly. I just moved the file definition lines like you suggested and it is great. I figured it was something simple like that. :)
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

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