K
Kent Schederin
Hi
I have written a function which i use in a loop to find a value from Sheets1
in a table in sheet 2. The function returns the rownumber
The function looks like this:
strRabattKod = Worksheets(1).Range("C" & i).Value
lngRadnr = Hittarad(strRabattKod)
Function Hittarad(Rabattgrupp As String) As Long
Dim c As Object
With Sheets(2).Range("E3" & ":I" & lngLastRowAvtal)
Set c = .Find(Rabattgrupp, LookIn:=xlValues)
If Not c Is Nothing Then
Hittarad = c.Row
End If
End With
End Function
Sometimes i must loop 50000 times and it takes a whole lot of time. Today
almost 30 minutes
Is there a faster way to find this value than using the Find method?
When the function has found the value I use an If-structure to LookUp a
value in one column the row that was found.
With Sheets(2)
If .Cells(lngRadnr, 2) = "J" Then
x = .Cells(lngRadnr, 9)
ElseIf .Cells(lngRadnr, 4) = "" And .Cells(lngRadnr, 5) <> "" Then
x = .Cells(lngRadnr, 6)
ElseIf .Cells(lngRadnr, 4) <> "" And .Cells(lngRadnr, 5) = "" Then
x = .Cells(lngRadnr, 8)
End If
Then it calculates with the x variable
With Sheets(1)
.Range("G" & i) = Format(x / 1000, "0 %")
.Range("H" & i) = Cells(i, 2) * (1 - x / 1000)
End With
Thanks for any advice
KS
I have written a function which i use in a loop to find a value from Sheets1
in a table in sheet 2. The function returns the rownumber
The function looks like this:
strRabattKod = Worksheets(1).Range("C" & i).Value
lngRadnr = Hittarad(strRabattKod)
Function Hittarad(Rabattgrupp As String) As Long
Dim c As Object
With Sheets(2).Range("E3" & ":I" & lngLastRowAvtal)
Set c = .Find(Rabattgrupp, LookIn:=xlValues)
If Not c Is Nothing Then
Hittarad = c.Row
End If
End With
End Function
Sometimes i must loop 50000 times and it takes a whole lot of time. Today
almost 30 minutes
Is there a faster way to find this value than using the Find method?
When the function has found the value I use an If-structure to LookUp a
value in one column the row that was found.
With Sheets(2)
If .Cells(lngRadnr, 2) = "J" Then
x = .Cells(lngRadnr, 9)
ElseIf .Cells(lngRadnr, 4) = "" And .Cells(lngRadnr, 5) <> "" Then
x = .Cells(lngRadnr, 6)
ElseIf .Cells(lngRadnr, 4) <> "" And .Cells(lngRadnr, 5) = "" Then
x = .Cells(lngRadnr, 8)
End If
Then it calculates with the x variable
With Sheets(1)
.Range("G" & i) = Format(x / 1000, "0 %")
.Range("H" & i) = Cells(i, 2) * (1 - x / 1000)
End With
Thanks for any advice
KS