I was looking to improve my code below to make even faster then what it currently is. I am a complete noob when it comes to Excel VBA and coding in general. I am sure their is ways to improve this code and make it run more efficiently. Specially opening and closing work books. Any help to improve this code would be greatly appreciated. My module one is Userform.show
On top of the code if anyone can help me with adding a progress bar or loading bar for the macro when its running, that would be a nice little touch.
Private Sub CommandButton1_Click()
Dim RawData As String, Report As String, RawDataWorkingFolder As String, ReportWorkingFolder As String, myrange As Range, cell As Range
Set aw = ActiveWorkbook
Application.ScreenUpdating = False
Set myrange = Worksheets("Sheet1").Range("INFO")
BD = TextBox1.Value
ED = TextBox2.Value
a = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
RawDataWorkingFolder = Trim(aw.Worksheets(1).Range("A1").Value)
RawData = Trim(aw.Worksheets(1).Range("E1").Value)
Call Utilities.OpenWorkbook(RawDataWorkingFolder & RawData)
Worksheets("DAILY").Select
Worksheets("DAILY").Range("C6:C219,D6:D219,F6:F219").Select
Selection.ClearContents
Call Utilities.CloseWorkbook(RawData)
Worksheets("Sheet1").Activate
Unload Me
For i = 2 To a
If myrange.Cells(i, 1).Value >= DateValue(BD) And myrange.Cells(i, 1).Value <= DateValue(ED) Then
If myrange.Cells(i, 5).Value = "ACH" Or myrange.Cells(i, 5).Value > 0 And myrange.Cells(i, 5).Value < 1000000 Then
des = myrange.Cells(i, 2)
Value = myrange.Cells(i, 4)
ACH = myrange.Cells(i, 5)
RawDataWorkingFolder = Trim(aw.Worksheets(1).Range("A1").Value)
RawData = Trim(aw.Worksheets(1).Range("E1").Value)
Call Utilities.OpenWorkbook(RawDataWorkingFolder & RawData)
Worksheets("DAILY").Select
Worksheets("DAILY").Range("D" & Rows.Count).End(xlUp).Offset(1) = des
Worksheets("DAILY").Range("F" & Rows.Count).End(xlUp).End(xlUp).Offset(1) = Value
Worksheets("DAILY").Range("C" & Rows.Count).End(xlUp).Offset(1) = ACH
Call Utilities.CloseWorkbook(RawData)
Worksheets("Sheet1").Activate
ElseIf myrange.Cells(i, 5).Value = "CREDIT" Then
des = myrange.Cells(i, 2)
Value = myrange.Cells(i, 3) * -1
ACH = myrange.Cells(i, 5)
RawDataWorkingFolder = Trim(aw.Worksheets(1).Range("A1").Value)
RawData = Trim(aw.Worksheets(1).Range("E1").Value)
Call Utilities.OpenWorkbook(RawDataWorkingFolder & RawData)
Worksheets("DAILY").Select
Worksheets("DAILY").Range("D" & Rows.Count).End(xlUp).Offset(1) = des
Worksheets("DAILY").Range("F" & Rows.Count).End(xlUp).End(xlUp).Offset(1) = Value
Worksheets("DAILY").Range("C" & Rows.Count).End(xlUp).Offset(1) = ACH
Worksheets("DAILY").Range("A1").Select
Call Utilities.CloseWorkbook(RawData)
Worksheets("Sheet1").Activate
End If
End If
Application.StatusBar = "Data is Running... Percentage complete is " & Round((i / a * 100), 0) & "%"
Next
MsgBox ("DONE, TRANSFERRED DATA FOR" & TextBox1)
End Sub