Working
with several ERP tools, I realized the importance of Database and how
easily database can be downloaded and uploaded into the ERP systems with
excel. Data
analysis and reporting is a cakewalk which is quite cumbersome and
highly processor intensive, if done in ERP systems. The process is quite
simple. Download Data in Excel format and do a post processing on it
using excel based macros. The knowledge of VBA and
Macros eases the post processing, graphical data representation,
dashboard development and data analytics.
I
encountered a similar type of situation where I had an excel base data
is a very crude format. The requirement was to re-arrange the data in a
predefined format
using key-identifier present in the same excel sheet. Data parsing
process and its arrangement was not too difficult, but it required lots
of VBA coding. The first major hurdle was to read the downloaded excel
sheet into my excel based application.
Here I present a sample code to read excel data, easily and efficiently, into an excel sheet.
Private Sub CMD_GO_Click()
‘THIS CODE ACTIVATES WHEN USER CLICKS ON “go” COMMAND BUTTON
‘THIS CODE ACTIVATES WHEN USER CLICKS ON “go” COMMAND BUTTON
Dim shtOrigin
As Worksheet
‘DEFINE ORIGIN SHEET
Dim shtDestin As Worksheet
‘DEFINE DESTINATION SHEET
Dim strFile As String
Dim Range1 As Range
Application.ScreenUpdating = False
‘PREVENT SCREEN UPDATING
Sheets.Add
‘ADDS A SHEET TO MACRO BASED EXCEL APPLICATION
ActiveSheet.Name = "Data"
‘ASSIGNS NAME data TO IT
Set shtDestin = ActiveWorkbook.ActiveSheet
‘ THIS IS DESTINATION SHEET
strFile = Application.GetOpenFilename
‘OPEN A EXPLORER TO LOCATE DOWNLOADED EXCEL SHEET
If CStr(strFile) <> "False" Then
Set shtOrigin = Workbooks.Open(strFile).Sheets(1)
shtOrigin.Range("A1").Select
shtOrigin.Range(Selection, Selection.Offset(0, 0).End(xlDown).End(xlToRight)).Select
‘COPYING
ENTIRE DATA FROM SOURCE EXCEL SHEET
Selection.Copy Destination:=shtDestin.Range("A1")
‘PASTING
DATA INTO DESTINATION SHEET
Application.CutCopyMode = False
ActiveWorkbook.Close False
Set shtOrigin = Nothing
Else
Application.ScreenUpdating = True
MsgBox "No valid file selected", vbOKOnly + vbInformation, "Copy Error"
End If
No_Of_Row = shtDestin.Range("A1000").End(xlUp).Row
‘COUNTS NUMBER OF ROWS
Set Ref_Range = shtDestin.Range("A1")
MsgBox "done"
'PASTE YOUR CODE FOR DATA PARSING AND POSTING
Application.DisplayAlerts = False
shtDestin.Delete
‘DELETES DESTINATION SHEET
‘IT IS NOT REQUIRED AS YOU HAVE FINISHED DATA PARSING AND DISPLAYING
Application.DisplayAlerts = True
Sheets("Sheet1").Columns("B").EntireColumn.AutoFit
End Sub
Happy VBA…ing..