SirGruffles
New Member
- Joined
- Jul 23, 2018
- Messages
- 26
Hello,
I'm new to VBA and trying to make a custom Dashboard for a manager.
Below lies my attempt at creating a data refresh and save macro that will be tied to a button on the "Dashboard" sheet.
My main question is: Am I actually calling the RefreshData() sub twice in WriteData(), thereby making the entire process twice as long?
I know the server some of my queries are connecting to is a tad slow, so I know that's part of my issue, but I want to make sure I'm not shooting myself in the foot with my own code.
I appreciate any help given.
If you have the spare time to find any other inefficiencies in my code, I would be greatly appreciative.
But I understand if that is technically out of scope for this forum request.
Thank you for your time.
I'm new to VBA and trying to make a custom Dashboard for a manager.
Below lies my attempt at creating a data refresh and save macro that will be tied to a button on the "Dashboard" sheet.
My main question is: Am I actually calling the RefreshData() sub twice in WriteData(), thereby making the entire process twice as long?
I know the server some of my queries are connecting to is a tad slow, so I know that's part of my issue, but I want to make sure I'm not shooting myself in the foot with my own code.
VBA Code:
Sub RefreshData()
Dim Quer As Long
With ThisWorkbook
For Quer = 1 To .Connections.Count
If .Connections(Quer).Type = xlConnectionTypeOLEDB Then
.Connections(Quer).OLEDBConnection.BackgroundQuery = False
End If
Next Quer
End With
ThisWorkbook.RefreshAll
End Sub
------------------------------------------------------------------------------------------------------
Sub WriteData()
Dim cell As Range
Dim cell2 As Range
Dim Daily As Object
Dim DataDate As Range
Dim answer As Integer
Set Daily = Sheets("Dashboard")
Set DataDate = Daily.Range("C4")
For Each cell In Sheets("YTD Data").Range("B8:B400")
If cell.Value = DataDate Then
If HasValue(Range(cell.Offset(0, 1), cell.Offset(0, 21))) Then
answer = MsgBox("There is data saved for this date already." & vbNewLine & "Do you wish to proceed?" & vbNewLine & "Continuing will overwrite current data!", vbQuestion + vbYesNo)
If answer = vbNo Then
MsgBox ("Refresh process cancelled.")
Exit Sub
Else: password = InputBox("Please enter data overwrite password.")
If password = "GoDiegoGo" Then
Call RefreshData
Else: password = MsgBox("Your entered password is incorrect." & vbNewLine & "Now ending refresh process.", vbOKOnly, "INCORRECT PASSWORD!")
Exit Sub
End If
End If
End If
End If
Next
Call RefreshData
Daily.Range("C9:V9").Copy
For Each cell2 In Sheets("YTD Data").Range("B8:B400")
If cell2.Value = DataDate Then
cell2.Offset(0, 1).PasteSpecial xlPasteValues
End If
Next
Worksheets("Dashboard").Activate
Application.CutCopyMode = False
Cells(3, 6).Value = Format(Now, "mm/dd/yyyy")
Cells(4, 6).Value = Format(Now, "hh:mm ampm")
ThisWorkbook.Save
MsgBox "\o/ Praise the Sun \o/"
End Sub
------------------------------------------------------------------------------------------------------
Function HasValue(rng As Range) As Boolean
HasValue = Not rng.Find(What:="*", LookIn:=xlValues) Is Nothing
End Function
I appreciate any help given.
If you have the spare time to find any other inefficiencies in my code, I would be greatly appreciative.
But I understand if that is technically out of scope for this forum request.
Thank you for your time.