Hi All,
Every day I am downloading data in one specific folder, which comes in csv format date wise, which means it changes everyday.
I already have VBA Code (below) which insert row at the last row of current sheet, insert today's day, lookup sheet name and extract its data from raw data(csv file) and lastly fill down the formulated upper row in last row of the sheet. This VBA works fine with current sheet and I need to switch every sheet for updating.
Now I need help in modifying this vba to update every sheet in workbook with just one command.
Your assistance will make my life more easier.
Sub Updates()
Dim n As Long, k As Long
Application.ScreenUpdating = True
Range(ActiveCell, ActiveCell.Offset(Val(1) - 1, 0)).EntireRow.Insert
k = ActiveCell.Offset(-1, 0).Row
n = Cells(k, 84).End(xlToLeft).Column
Range(Cells(k, 84), Cells(k + Val(1), n)).FillDown
With ActiveCell
.Value = Format(Date, "dd-mmm-yy")
.Offset(0, 1).Value = "MH"
End With
Dim SheetName As String
Dim ActiveDate As String
PathO = "C:\RawData\"
SheetName = ActiveSheet.Name
ActiveDate = Cells(ActiveCell.Row, 1)
DD = Mid(ActiveDate, 1, 2)
MM = Mid(ActiveDate, 4, 3)
YY = Mid(ActiveDate, 8, 2)
If MM = "Jan" Then MMO = "01"
If MM = "Feb" Then MMO = "02"
If MM = "Mar" Then MMO = "03"
If MM = "Apr" Then MMO = "04"
If MM = "May" Then MMO = "05"
If MM = "Jun" Then MMO = "06"
If MM = "Jul" Then MMO = "07"
If MM = "Aug" Then MMO = "08"
If MM = "Sep" Then MMO = "09"
If MM = "Oct" Then MMO = "10"
If MM = "Nov" Then MMO = "11"
If MM = "Dec" Then MMO = "12"
FileNameO = PathO + "EQ" + DD + MMO + YY + ".CSV"
If Dir(FileNameO) = "" Then
MsgBox "File Doesn't Exist (" + FileNameO + ")"
Exit Sub
End If
SheetName = UCase(SheetName)
Open FileNameO For Input As #1
While Not EOF(1)
Input #1, A1$, A2$, A3$, A4$, A5$, A6$, A7$, A8$, A9$, A10$, A11$, A12$, A13$, A14$
If A2 = SheetName Then
Cells(ActiveCell.Row, 2) = A5$
Cells(ActiveCell.Row, 3) = A6$
Cells(ActiveCell.Row, 4) = A7$
Cells(ActiveCell.Row, 5) = A8$
Cells(ActiveCell.Row, 6) = A12$
Close #1
Exit Sub
End If
Wend
Close #1
End Sub
Every day I am downloading data in one specific folder, which comes in csv format date wise, which means it changes everyday.
I already have VBA Code (below) which insert row at the last row of current sheet, insert today's day, lookup sheet name and extract its data from raw data(csv file) and lastly fill down the formulated upper row in last row of the sheet. This VBA works fine with current sheet and I need to switch every sheet for updating.
Now I need help in modifying this vba to update every sheet in workbook with just one command.
Your assistance will make my life more easier.
Code:
Dim n As Long, k As Long
Application.ScreenUpdating = True
Range(ActiveCell, ActiveCell.Offset(Val(1) - 1, 0)).EntireRow.Insert
k = ActiveCell.Offset(-1, 0).Row
n = Cells(k, 84).End(xlToLeft).Column
Range(Cells(k, 84), Cells(k + Val(1), n)).FillDown
With ActiveCell
.Value = Format(Date, "dd-mmm-yy")
.Offset(0, 1).Value = "MH"
End With
Dim SheetName As String
Dim ActiveDate As String
PathO = "C:\RawData\"
SheetName = ActiveSheet.Name
ActiveDate = Cells(ActiveCell.Row, 1)
DD = Mid(ActiveDate, 1, 2)
MM = Mid(ActiveDate, 4, 3)
YY = Mid(ActiveDate, 8, 2)
If MM = "Jan" Then MMO = "01"
If MM = "Feb" Then MMO = "02"
If MM = "Mar" Then MMO = "03"
If MM = "Apr" Then MMO = "04"
If MM = "May" Then MMO = "05"
If MM = "Jun" Then MMO = "06"
If MM = "Jul" Then MMO = "07"
If MM = "Aug" Then MMO = "08"
If MM = "Sep" Then MMO = "09"
If MM = "Oct" Then MMO = "10"
If MM = "Nov" Then MMO = "11"
If MM = "Dec" Then MMO = "12"
FileNameO = PathO + "EQ" + DD + MMO + YY + ".CSV"
If Dir(FileNameO) = "" Then
MsgBox "File Doesn't Exist (" + FileNameO + ")"
Exit Sub
End If
SheetName = UCase(SheetName)
Open FileNameO For Input As #1
While Not EOF(1)
Input #1, A1$, A2$, A3$, A4$, A5$, A6$, A7$, A8$, A9$, A10$, A11$, A12$, A13$, A14$
If A2 = SheetName Then
Cells(ActiveCell.Row, 2) = A5$
Cells(ActiveCell.Row, 3) = A6$
Cells(ActiveCell.Row, 4) = A7$
Cells(ActiveCell.Row, 5) = A8$
Cells(ActiveCell.Row, 6) = A12$
Close #1
Exit Sub
End If
Wend
Close #1
End Sub