Date - Driving me mad!

bposaner

Board Regular
Joined
May 28, 2002
Messages
74
Hi, i'm getting all stuck and cant find my way out HELP!
I am reading in files 1-31 using a counter and loop, which are days of the month. Before doing the business I need to exclude weekends and I'm trying to build a date and dump the ones over the weekend. you'll see below my poor attempt.

But i cant seem to figure this out. I'm sure its a simple one, but I'm a VBA dullard!!

Any help would be tops.
Thanks
Ben

Code:
For counter2 = 1 To 31

          mm = Val(Mid(DateRun, 1, 2))
          yyyy = Val(Mid(DateRun, 5, 4))
            dd = counter2
       
        dateChk = mm & dd & yyyy
        DayChk = Weekday(dateChk, vbMonday)
        If DayChk < 6 Then
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
If I understood it correctly, what you want is:

dateChk = DateSerial(Year(yyyy), Month(mm), Day(dd))
 
Upvote 0
DateChk shows a value of 00:00:00, not sure why.
So when it goes into excel its not the correct date.

Code:
Sub TopTrans()

Dim Message, Title, Default, DateBox, dateChk As Date
Message = "Enter date required in mmyyyy format."  
Title = "DateRun" 
Default = "102005"  


DateRun = InputBox(Message, Title, Default)

Windows("TopTrans.xls").Activate
Sheets("Sheet1").Name = "" & DateRun & ""

For counter2 = 1 To 31

            mm = Val(Mid(DateRun, 1, 2))
          yyyy = Val(Mid(DateRun, 3, 4))
            dd = counter2
       
        dateChk = DateSerial(Year(yyyy), Month(mm), Day(dd))

        DayChk = Weekday(dateChk, vbMonday)
        If DayChk < 6 Then
        
            Workbooks.OpenText Filename:= _
        "G:\" & DateRun & "\" & counter2 & ".dat" _
        , Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:= _
        Array(Array(0, 9), Array(1, 1), Array(10, 1), Array(21, 1), Array(31, 1))


Region = Cells(1, 1)
For Counter1 = 1 To 65000
    If Cells(Counter1, 1) = "" Then
        If Cells(Counter1, 2) = "" Then Exit For
        Cells(Counter1, 1) = Region
    Else
         Region = Cells(Counter1, 1)     'Workbooks("TopTrans.xls").Sheets("sheet1").
    End If
     
    If Cells(Counter1, 4) = "" Then
       Cells(Counter1, 5) = ""
    Else
        Cells(Counter1, 5) = "" & dateChk & ""
    End If
    
    If Cells(Counter1, 2) = "" Then
        Cells(Counter1, 1) = ""
    End If
    
Next Counter1
Close
        
        
        End If
Next counter2
      

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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