Hello,
I am trying to write a code to store a set of data into an array and finally generate a report in excel.
The main database has several category of rows.
My code checks for a certain value (where Col "category2 = Legal", stores specific values from corresponding row into variables.
I have been able to do store values needed successfully.
Now would like to basically have all the values in an array so this can be used to generate an excel report.
Problem I am facing is :
The value when being assigned to the array doesn't seem to work and therefore nor am i able to display in msgbox.
Attaching code below.
Any help would be greatly appreciated specially if there is an easier way to do this whole code using a different approach.
I need to generate several reports like this and generate automated emails.
Thanks in Advance
Anshika
I am trying to write a code to store a set of data into an array and finally generate a report in excel.
The main database has several category of rows.
My code checks for a certain value (where Col "category2 = Legal", stores specific values from corresponding row into variables.
I have been able to do store values needed successfully.
Now would like to basically have all the values in an array so this can be used to generate an excel report.
Problem I am facing is :
The value when being assigned to the array doesn't seem to work and therefore nor am i able to display in msgbox.
Attaching code below.
Any help would be greatly appreciated specially if there is an easier way to do this whole code using a different approach.
I need to generate several reports like this and generate automated emails.
Thanks in Advance
Anshika
VBA Code:
Sub COURTDATE()
'
' COURTDATE Macro
'
'
Worksheets("Database").Activate
'ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:= _
"COURT DATE"
'ActiveWindow.SmallScroll ToRight:=20
Dim record_count As Integer
record_count = WorksheetFunction.CountA(Range("b:b"))
record_count = record_count + 1
MsgBox "Total Records " & record_count
Dim ColCat2 As Integer
Dim ColCat3 As Integer
Dim ColDueDate As Integer
Dim ColCatStatus As Integer
Dim ColCourtCases As Integer
ColCat2 = WorksheetFunction.Match("CATEGORY2", ActiveWorkbook.Sheets("DATABASE").Range("1:1"), 0)
ColCat3 = WorksheetFunction.Match("CATEGORY3", ActiveWorkbook.Sheets("DATABASE").Range("1:1"), 0)
ColDueDate = WorksheetFunction.Match("DUE*DATE", ActiveWorkbook.Sheets("DATABASE").Range("1:1"), 0)
ColDueDays = WorksheetFunction.Match("DUE*DAY*", ActiveWorkbook.Sheets("DATABASE").Range("1:1"), 0)
ColCatStatus = WorksheetFunction.Match("STATUS", ActiveWorkbook.Sheets("DATABASE").Range("1:1"), 0)
ColCourtCases = WorksheetFunction.Match("*COURT*CASE*", ActiveWorkbook.Sheets("DATABASE").Range("1:1"), 0)
Dim Cat2 As String
Dim Cat3 As String
Dim Duedate As Date
Dim DueDays As Integer
Dim Status As String
Dim Courtcase As String
Dim Legalcases As Integer
Legalcases = WorksheetFunction.CountIf(Range("b:b"), "Legal")
MsgBox "No of Court Cases are " & Legalcases
MsgBox record_count
'MsgBox ColCat2 & ColCat3 & ColDueDate & ColCatStatus & ColCourtCases & Cat2 & Cat3
Dim j As Integer
j = 2
Dim z As Integer
z = 0
Do While j <= record_count
'Dim Value As String
'Value = Cells(j, ColCat2).Value
'MsgBox Value
If Cells(j, ColCat2).Value = "LEGAL" Then
'MsgBox Cells(j, ColCat2).Value & "Yes"
Cat2 = Cells(j, ColCat2).Value
Cat3 = Cells(j, ColCat3).Value
Duedate = Cells(j, ColDueDate).Value
DueDays = Cells(j, ColDueDays).Value
Status = Cells(j, ColCatStatus).Value
Courtcase = Cells(j, ColCourtCases).Value
'MsgBox Cat2 & vbCrLf & Cat3 & vbCrLf & Duedate & vbCrLf & vbCrLf & Status & vbCrLf & Courtcase
Dim MyArray(5, 49) As Variant
'Dim dummy As String
'dummy = Courtcase
'MsgBox dummy
MyArray(z, 0) = Cat2
MyArray(z, 1) = Cat3
MyArray(z, 2) = Duedate
MyArray(z, 3) = DueDays
MyArray(z, 4) = Status
MyArray(z, 5) = Courtcase
z = z + 1
MsgBox "Value stored in MyArray(" & z & ",0): " & MyArray(z, 0)
End If
j = j + 1
Loop
End Sub
Last edited by a moderator: