I have a SUMPRODUCT formula that checks three criteria and multiples values accordingly. It takes quite some time to do these calculations due to the amount of information and steps it has to go through. My goal is to convert this SUMPRODUCT formula into a VBA code to reduce the size of the workbook and make it faster. Unfortunately I got stuck:( My code so far is able to select the right range...but how do I convert my sumproduct formula into excel?
Here is the code I would like to convert:
Here is what I have so far:
Please see attachment to get an idea of what I am trying to accomplish.
Here is the code I would like to convert:
Code:
=SUMPRODUCT(($A6=Database!$A$5:$A$5001)*(REG!D$5=Database!$B$5:$B$5001)*(Database!$C$5:$C$5001)*(Database!$D$5:$D$5001=."r"))
Code:
Private Sub updateworksheet()
Dim eenumber As Range
Dim unitnumber As Range
Dim eehours As Range
Dim hourtype As Range
Dim lastrowdata As Integer
Dim rng2 As Range
Dim findstring As String
Dim rangereg As Range
Dim columnindex As Integer
Dim rowindex As Integer
Sheets("Database").Activate
lastrowdata = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
Set eenumber = ActiveSheet.Range("A5:A" & lastrowdata)
Set unitnumber = ActiveSheet.Range("B5:B" & lastrowdata)
Set eehours = ActiveSheet.Range("C5:C" & lastrowdata)
Set hourtype = ActiveSheet.Range("D5:D" & lastrowdata)
findstring = "Copy"
Set rng2 = Sheets("REG").Range("5:5").Find(findstring, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext _
, MatchCase:=False)
If rng2 Is Nothing Then
Else
Sheets("REG").Activate
rowindex = ActiveSheet.Range("A65536").End(xlUp).Row - 2
columnindex = rng2.Offset(1, 0).Column
Set rangereg = rng2.Offset(1, 0).End(xlDown)
ActiveSheet.Range(Cells(6, 4), Cells(rowindex, columnindex)).Select
End If
End Sub