Hi,
I am new to the forum and also to creating macros in excel with vba.
I have a similar problem to many people around this forum, but the answers i read didn't seem to help my case. The thing is that i have two sheets which have tens of thousand lines each. In one of them I have the id_number of water pipes, and on another I have the measured presure (the thing is that the presure is not measured in all pipes, so not all have a correspondence).
I used this vlookup to match the presure to the pipe. I works perfectly until it encounters a pipe with no measured presure, then there is an error and it crashes. I tried with IsError in my function, but function crashes and exits at the line before it reaches it.
I also tried to use Application.VLookup() instead of Application.WorksheetFunction.VLookup() but it crashed too, give me an Error 13.
Please help, I dont know where more to look for answer. Thanks!
Sub prueba()
Dim result As String
Dim shcalc As Worksheet
Dim shvalores As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False
Set shcalc = ActiveWorkbook.Sheets("Calculo")
Set shvalores = ActiveWorkbook.Sheets("Variabilidad")
i = 3
While shcalc.Cells(i, 1).Value <> Empty
result = 0
result = Application.WorksheetFunction.VLookup(shcalc.Cells(i, 1), shvalores.Range("A2:B31"), 2, False)
If IsError(result) Then
result = 0
ElseIf result > 0 Then
shcalc.Cells(i, 37).Value = result
End If
i = i + 1
Wend
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
I am new to the forum and also to creating macros in excel with vba.
I have a similar problem to many people around this forum, but the answers i read didn't seem to help my case. The thing is that i have two sheets which have tens of thousand lines each. In one of them I have the id_number of water pipes, and on another I have the measured presure (the thing is that the presure is not measured in all pipes, so not all have a correspondence).
I used this vlookup to match the presure to the pipe. I works perfectly until it encounters a pipe with no measured presure, then there is an error and it crashes. I tried with IsError in my function, but function crashes and exits at the line before it reaches it.
I also tried to use Application.VLookup() instead of Application.WorksheetFunction.VLookup() but it crashed too, give me an Error 13.
Please help, I dont know where more to look for answer. Thanks!
Sub prueba()
Dim result As String
Dim shcalc As Worksheet
Dim shvalores As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False
Set shcalc = ActiveWorkbook.Sheets("Calculo")
Set shvalores = ActiveWorkbook.Sheets("Variabilidad")
i = 3
While shcalc.Cells(i, 1).Value <> Empty
result = 0
result = Application.WorksheetFunction.VLookup(shcalc.Cells(i, 1), shvalores.Range("A2:B31"), 2, False)
If IsError(result) Then
result = 0
ElseIf result > 0 Then
shcalc.Cells(i, 37).Value = result
End If
i = i + 1
Wend
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub