VBA To Update Every Sheet in Workbook

Shums

New Member
Joined
Jul 24, 2011
Messages
18
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.

Code:
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
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,224,551
Messages
6,179,473
Members
452,915
Latest member
hannnahheileen

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