Mark_Annonyous
New Member
- Joined
- May 9, 2020
- Messages
- 20
- Office Version
- 365
- Platform
- Windows
Hi Peeps,
Like most people, i just use the same code over and over again, tweaking it as necessary, but I've hit a block when going from sum to Max.
It seems to be pulling the max value of Zero, and the first in the list that meets the criteria.
Any ideas?
Hope everyone is well!
Like most people, i just use the same code over and over again, tweaking it as necessary, but I've hit a block when going from sum to Max.
It seems to be pulling the max value of Zero, and the first in the list that meets the criteria.
Any ideas?
Hope everyone is well!
Rich (BB code):
Sub STRUCAV()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim DataImportCounter, RowCounter, ColumnCounter, LastRowDataImport, LastRow As Integer
Dim VName As String
Dim AvailDate As Date
LastRowDataImport = FindLastRow("Inputs")
With Worksheets("Inputs")
Reutdata = Range(.Cells(1, 1), .Cells(LastRowDataImport, 570))
End With
LastRowSummary = FindLastRow2("Sheet2")
With Worksheets("Sheet2")
alldata = Range(.Cells(1, 1), .Cells(LastRowSummary, 570))
output1 = Range(.Cells(12, 6), .Cells(LastRowSummary, 570))
For ColumnCounter = 6 To 570
Exportdate = alldata(1, ColumnCounter)
For RowCounter = 12 To LastRowSummary
Maxfix = 0
VName = alldata(RowCounter, 1) 'For each cell being evaluated, we need to store the Export country in column 1 to be evaluated.
For DataImportCounter = 1 To LastRowDataImport
If Reutdata(DataImportCounter, 3) = VName Then
If Exportdate >= Reutdata(DataImportCounter, 45) And Exportdate <= Reutdata(DataImportCounter, 46) Then
Maxfix = WorksheetFunction.Max(Reutdata(DataImportCounter, 48))
End If
End If
Next DataImportCounter
output1(RowCounter - 11, ColumnCounter - 5) = Maxfix
Next RowCounter
Next ColumnCounter
Range(.Cells(12, 6), .Cells(LastRowSummary, 570)) = output1
End With
Application.ScreenUpdating = True
End Sub
Function FindLastRow(ShtName) As Integer
For X = 1 To 25000
If Sheets(ShtName).Cells(X, 1) = "" Then
Exit For
End If
Next X
FindLastRow = X - 1
End Function
Function FindLastRow2(ShtName) As Integer
For X = 12 To 2000
If Sheets(ShtName).Cells(X, 1).Value = "" Then
Exit For
End If
Next X
FindLastRow2 = X - 1
End Function
Last edited by a moderator: