Mark_Annonyous
New Member
- Joined
- May 9, 2020
- Messages
- 20
- Office Version
- 365
- Platform
- Windows
I am going through a journey of better understanding VBA, and like all things in life, you feel like your shoveling the proverbial up a hill until you start jumping hurdles.
Well, this is my first worksheet funtion, as the oriignal i wrote, which worked, took to long to run (30 mins)
The error i am getting is method range object: Global fail.
Below is my code, please be nice
Sub Countavol()
Dim DataImportCounter, RowCounter, ColumnCounter, ExShipCount, ImShipCount, LastRowDataImport, LastRow As Integer
Dim ExportCountry, ImportCountry As String
Dim Exportdate As Date
LastRowDataImport = FindLastRow("REUTERS IMPORT") 'Loop for lookup
LastRowSummary = Findlastrowtable("SUMMARY DATA EXPORT VIEW") ' Loop for table.
For ColumnCounter = 10 To 33 ' Colums where summary table preside.
Exportdate = Sheets("SUMMARY DATA EXPORT VIEW").Cells(1, ColumnCounter).Value
For RowCounter = 81 To LastRowSummary ' This is th3 first cell to be evluated. For each colum
ExShipCount = 0
Exportdate = Sheets("SUMMARY DATA EXPORT VIEW").Cells(1, ColumnCounter).Value '
ExportCountry = Sheets("SUMMARY DATA EXPORT VIEW").Cells(RowCounter, 1).Value 'For each cell being evaluated, we need to store the Export country in column 1 to be evaluated.
ImportCountry = Sheets("SUMMARY DATA EXPORT VIEW").Cells(RowCounter, 2).Value 'For each cell being evaluated, we need to store the Import country in column 2 to be evaluated.
For DataImportCounter = 1 To LastRowDataImport ' Data import counter is delared as rows 1 to the outcome of the function FINDLASTROW
ExShipCount = WorksheetFunction.CountIfs(Range(Sheets("REUTERS IMPORT").Cells(DataImportCounter, 8)) = ExportCountry, Range(Sheets("REUTERS IMPORT").Cells(DataImportCounter, 10)) = ImportCountry, Range(Exportdate = Sheets("REUTERS IMPORT").Cells(DataImportCounter, 16)))
Next DataImportCounter
Sheets("SUMMARY DATA EXPORT VIEW").Cells(RowCounter, ColumnCounter) = ExShipCount ' Where to put the restuls. Colum counter and
Next RowCounter 'Once we Finish with the rows we move to the colums
Next ColumnCounter
End Sub
Function FindLastRow(ShtName) As Integer
For X = 81 To 50000
If Sheets(ShtName).Cells(X, 1) = "" Then
Exit For
End If
Next X
FindLastRow = X - 1
End Function
Function Findlastrowtable(ShtName) As Integer
For X = 81 To 50000
If Sheets(ShtName).Cells(X, 1).Value = "x" Then
Exit For
End If
Next X
Findlastrowtable = X - 1
End Function
Well, this is my first worksheet funtion, as the oriignal i wrote, which worked, took to long to run (30 mins)
The error i am getting is method range object: Global fail.
Below is my code, please be nice
Sub Countavol()
Dim DataImportCounter, RowCounter, ColumnCounter, ExShipCount, ImShipCount, LastRowDataImport, LastRow As Integer
Dim ExportCountry, ImportCountry As String
Dim Exportdate As Date
LastRowDataImport = FindLastRow("REUTERS IMPORT") 'Loop for lookup
LastRowSummary = Findlastrowtable("SUMMARY DATA EXPORT VIEW") ' Loop for table.
For ColumnCounter = 10 To 33 ' Colums where summary table preside.
Exportdate = Sheets("SUMMARY DATA EXPORT VIEW").Cells(1, ColumnCounter).Value
For RowCounter = 81 To LastRowSummary ' This is th3 first cell to be evluated. For each colum
ExShipCount = 0
Exportdate = Sheets("SUMMARY DATA EXPORT VIEW").Cells(1, ColumnCounter).Value '
ExportCountry = Sheets("SUMMARY DATA EXPORT VIEW").Cells(RowCounter, 1).Value 'For each cell being evaluated, we need to store the Export country in column 1 to be evaluated.
ImportCountry = Sheets("SUMMARY DATA EXPORT VIEW").Cells(RowCounter, 2).Value 'For each cell being evaluated, we need to store the Import country in column 2 to be evaluated.
For DataImportCounter = 1 To LastRowDataImport ' Data import counter is delared as rows 1 to the outcome of the function FINDLASTROW
ExShipCount = WorksheetFunction.CountIfs(Range(Sheets("REUTERS IMPORT").Cells(DataImportCounter, 8)) = ExportCountry, Range(Sheets("REUTERS IMPORT").Cells(DataImportCounter, 10)) = ImportCountry, Range(Exportdate = Sheets("REUTERS IMPORT").Cells(DataImportCounter, 16)))
Next DataImportCounter
Sheets("SUMMARY DATA EXPORT VIEW").Cells(RowCounter, ColumnCounter) = ExShipCount ' Where to put the restuls. Colum counter and
Next RowCounter 'Once we Finish with the rows we move to the colums
Next ColumnCounter
End Sub
Function FindLastRow(ShtName) As Integer
For X = 81 To 50000
If Sheets(ShtName).Cells(X, 1) = "" Then
Exit For
End If
Next X
FindLastRow = X - 1
End Function
Function Findlastrowtable(ShtName) As Integer
For X = 81 To 50000
If Sheets(ShtName).Cells(X, 1).Value = "x" Then
Exit For
End If
Next X
Findlastrowtable = X - 1
End Function