I am a novice at excel vba and array's.
I want to be able to loop thru the wrkshts in the array and pass that wrksht as a variable to my formulas(if i even have those setup correctly) for processing of capturing cell range data for each of the worksheets from month to month basis. I need some serious help getting on track and headed in the right direction. I appreciate your assistance with this. Thanks
I want to be able to loop thru the wrkshts in the array and pass that wrksht as a variable to my formulas(if i even have those setup correctly) for processing of capturing cell range data for each of the worksheets from month to month basis. I need some serious help getting on track and headed in the right direction. I appreciate your assistance with this. Thanks
Code:
Private Sub CommandButton1_Click()
Dim vDate
Dim vLinkPath
Dim vMonth1
Dim vYear1
Dim vStatus
Dim i As Integer
Dim ShtArr As Variant
vDate = ActiveSheet.Range("A1")
vLinkPath = ActiveSheet.Range("A13")
If IsDate(vDate) = False Then
MsgBox "You must first enter an Date for this workbook in cell A1.", vbExclamation, "Missing Data"
Range("A1").Select
Exit Sub
End If
If IsEmpty(vLinkPath) = True Then
MsgBox "You must first enter an Archive File Directory for Education Monthly Report in cell A13.", vbExclamation, "Missing Data"
Range("A13").Select
Exit Sub
End If
vMonth1 = MonthName(Month(DateAdd("m", -1, vDate)))
vYear1 = Format(DateAdd("m", -1, vDate), "yyyy")
ShtArr = Array("BCC", "BCFC", "EKCC", "FCDC", "GRCC", "KCIW", "KSP", "KSR", "LEA", "LLCC", "LSCC", "MAC", "NTC", "OCCC", "RCC", "WKCC")
For i = LBound(ShtArr) To UBound(ShtArr)
With Sheets(arr(i))
.Unprotect
If Month(vDate) = 10 Then
Range("B4:J4").Formula = "='ShtArr'!R4C2:R4C10"
Range("B7:J7").Formula = "='ShtArr'!R7C2:R7C10"
Range("D12").Formula = "='ShtArr'!D12"
Range("G15").Formula = "='ShtArr'!G15"
Else
Range("B4:J4").Formula = "=(B4:J4)+'" + vLinkPath + vYear1 + "\[" + vMonth1 + " " + vYear1 + ".xls]ShtArr'!R4C2:R4C10"
Range("B7:J7").Formula = "=(B4:J4)+'" + vLinkPath + vYear1 + "\[" + vMonth1 + " " + vYear1 + ".xls]ShtArr'!R7C2:R7C10"
Range("D12").Formula = "=D12+'" + vLinkPath + vYear1 + "\[" + vMonth1 + " " + vYear1 + ".xls]ShtArr'!D12"
Range("G15").Formula = "=G15+'" + vLinkPath + vYear1 + "\[" + vMonth1 + " " + vYear1 + ".xls]ShtArr'!G15"
End If
vStatus = "Links to external workbooks are set, based on " + MonthName(Month(vDate)) + " " + Format(vDate, "yyyy") + "."
'Sheets("ShtArr").Protect DrawingObjects:=True
.Protect DrawingObjects:=True
End With
Next
ActiveSheet.Unprotect
With ActiveSheet
.Range("A18") = vStatus
.Range("A18").Font.ColorIndex = 0
.Range("A18").Interior.ColorIndex = 15
End With
Range("A1").Select
ActiveSheet.Protect DrawingObjects:=True
MsgBox vStatus, vbInformation, "Setup Complete"
End Sub