Hello guys,
I have a problem within the attached file with 1 line here below:
Private Sub CommandButton2_Click()
'Integers of weight calculator
Dim compareValue As Double
Dim roundUpValue As Double
Dim searchRange As Range
Dim resultCell As Range
Dim Ceiling As Double
'Integers of cost findig tool
Dim HomeSheet As Worksheet
Dim gltSheet As Worksheet
Dim HomeRange As Range
Dim GLTRange As Range
Dim resultRange As Range
Dim r&, c&
Set HomeSheet = ThisWorkbook.Sheets("Home")
Set gltSheet = ThisWorkbook.Sheets("GLT")
Set HomeRange = HomeSheet.Range("I12")
Set GLTRange = gltSheet.Range("A4:A254")
Set resultRange = HomeSheet.Range("I19")
'1) Calculation of the chargeable weight based on loading meter
compareValue = Application.WorksheetFunction.Max(Range("I11"), Range("I12"))
' Finds the higher number of weight and loading meter
roundUpValue = WorksheetFunction.Ceiling(compareValue, 100)
' Rounds up the higher value to the next whole hundred
Range("Y1") = WorksheetFunction.Ceiling(compareValue, 100)
' Gives the the rounded up number to control cell
Set searchRange = Sheets("GLT").Range("A4:A254")
' Defines the range, where to find the rounded up value
Set resultCell = searchRange.Find(roundUpValue)
'If Not resultCell Is Nothing Then
' Do something with the found value
' For example, display it in a message box
'MsgBox resultCell.Value
'Else
' Value not found in the specified range
' Do something else
'MsgBox "HIBA"
'Exit Sub
'End If
Set gltSheet = ThisWorkbook.Sheets("GLT")
'2) Finds the rate based on calculated chargeable weight
'Cross the cells of A4:A254 and B3:CT03 for the matching result
r = GLTRange.Find(HomeRange, , , 1).Row
c = gltSheet.Range("A3:CT254").Find(resultRange, , , 1).Column
'Value written in cell
HomeSheet.Range("I28 ").Value = gltSheet.Cells(r, c).Value
HomeSheet.Range("H53 ").Value = gltSheet.Cells(r, c).Value
HomeSheet.Range("H28 ").Value = "GLT"
HomeSheet.Range("D53 ").Value = "GLT"
'Pop-up Box of result with diesel surcharge
MsgBox " Freight charges are " & HomeSheet.Range("I28") & " ,-€ with trucker " & HomeSheet.Range("H28")
End Sub
The error happens every second day, meaning, sometimes run correctly but mostly not. I can't release my code so.
The debugger says, r & c are not set in row:
r = GLTRange.Find(HomeRange, , , 1).Row
c = gltSheet.Range("A3:CT254").Find(resultRange, , , 1).Column
The task would be to find the matching price level on GLT tab, based on cargo details entered by users.
Is there another workaround to find column/row matching value?
Thanks for checking!
Bookmarks