Hi.
My code returns the wrong cell values, but only sometimes, depending on the value it is looking for and i cant seem to find out why.
The Code looks in sheet("varenumre") for a number like you see below and returns a text in one cell and a number in the other:
For example if it lookup 81402.02 it does not return, AB 11t Granit 70/100 RA30, 1007530
But instead it returns, AB 11t granit 70/100, 1001013
However if it looks for 81201.44 it returns the correct values.
I am new to VBA and the code is a mix from different online searches.
The entire code:
Sub xopslag()
Dim markedcell As Range
Dim materiale As Range
Dim varenummer As Range
Set markedcell = ActiveCell
Set materiale = markedcell.Offset(, -1)
Set varenummer = markedcell.Offset(, 1)
If Not Application.Intersect(ActiveCell, Range("H2:H1000")) Is Nothing Then
On Error Resume Next
materiale.Value = WorksheetFunction.Lookup(markedcell.Value, Sheets("varenumre").Range("A2:A500"), Sheets("varenumre").Range("B2:B500"))
varenummer.Value = WorksheetFunction.Lookup(markedcell.Value, Sheets("varenumre").Range("A2:A500"), Sheets("varenumre").Range("C2:C500"))
If Err.Number <> 0 Then
MsgBox ("Wong number !")
End If
On Error GoTo 0
Else
MsgBox ("Stay on cell" & vbCrLf & " " & vbCrLf & "Remember to type number!")
End If
End Sub
Thanks a bunch
My code returns the wrong cell values, but only sometimes, depending on the value it is looking for and i cant seem to find out why.
The Code looks in sheet("varenumre") for a number like you see below and returns a text in one cell and a number in the other:
81201.04 | AB 6t granit 160/220 RA15 | 1007409 |
81201.44 | AB 6t granit 160/220 P-flex RA15 | 1007411 |
81402.02 | AB 11t Granit 70/100 RA30 | 1007530 |
81402.42 | AB 11t granit 70/100 P-flex RA30 | 1007533 |
81401.42 | AB 11t granit 70/100 P-flex RA15 | 1007526 |
51400.02 | AB 11t granit 70/100 | 1001013 |
For example if it lookup 81402.02 it does not return, AB 11t Granit 70/100 RA30, 1007530
But instead it returns, AB 11t granit 70/100, 1001013
However if it looks for 81201.44 it returns the correct values.
I am new to VBA and the code is a mix from different online searches.
The entire code:
Sub xopslag()
Dim markedcell As Range
Dim materiale As Range
Dim varenummer As Range
Set markedcell = ActiveCell
Set materiale = markedcell.Offset(, -1)
Set varenummer = markedcell.Offset(, 1)
If Not Application.Intersect(ActiveCell, Range("H2:H1000")) Is Nothing Then
On Error Resume Next
materiale.Value = WorksheetFunction.Lookup(markedcell.Value, Sheets("varenumre").Range("A2:A500"), Sheets("varenumre").Range("B2:B500"))
varenummer.Value = WorksheetFunction.Lookup(markedcell.Value, Sheets("varenumre").Range("A2:A500"), Sheets("varenumre").Range("C2:C500"))
If Err.Number <> 0 Then
MsgBox ("Wong number !")
End If
On Error GoTo 0
Else
MsgBox ("Stay on cell" & vbCrLf & " " & vbCrLf & "Remember to type number!")
End If
End Sub
Thanks a bunch