H
Hari Prasadh
Hi,
I want to do error handling when Im using Match function (last line in the
below code). Please note the code below is part of a bigger code.
What happens is that if -- ActiveCell.Value -- doesnt exist in the
ange --- ThisWorkbook.Sheets(lookingupsheetname).Range("i2:i" &
RownumberofLastBaseattribute) -- then I get an error saying
-- Run-time error 1004 unable to get the match property of the worksheet
function class. This happens EVEN AFTER I added an -- On error go to
errorreading: -- but somehow it doesnt work.
(What I wanted is that if there is an error then in the Activecell a comment
is added giving some warning.)
a) Why is my On Error not go to not working?
b) Also, how to specify in the code that Error handler is supposed to add
only a comment and after that the normal code execution should resume ?
Please guide me.
Sub MainActualUpcodes()
Dim NameOfOSWorkbook As String
Dim sh As Worksheet
Dim r As Integer
Dim opi As Integer
Dim lookingupsheetname As String
Dim RownumberofLastBaseattribute As Integer
Dim vlookuprowthroughMatch As String
NameOfOSWorkbook = "Open end data (OS).xls"
Application.ScreenUpdating = False
Workbooks(NameOfOSWorkbook).Activate
For Each sh In Workbooks(NameOfOSWorkbook).Worksheets
Worksheets(sh.Name).Activate
r = Range("A65536").End(xlUp).Row
opi = ThisWorkbook.Worksheets("Input Sheet").Range("M65536").End(xlUp).Row
lookingupsheetname = WorksheetFunction.VLookup(sh.Name,
ThisWorkbook.Worksheets("Input Sheet").Range("m7:n" & opi), 2, False)
RownumberofLastBaseattribute =
ThisWorkbook.Sheets(lookingupsheetname).Range("i65536").End(xlUp).Row
On error go to Errorreading:
vlookuprowthroughMatch = WorksheetFunction.Match(ActiveCell.Value,
ThisWorkbook.Sheets(lookingupsheetname).Range("i2:i" &
RownumberofLastBaseattribute), 0)
' some code
'
ErrorReading:
With ActiveCell.AddComment
.Visible = True
.Text Text:="Warning:" & Chr(10) & "The mentioned attribute
doesnt exist in the Base Upcode List " _
& Chr(10) & "Update the Base list and re-run the macro"
End With
'some code
'some code
Next sh
End sub
Thanks a lot,
Hari
India
I want to do error handling when Im using Match function (last line in the
below code). Please note the code below is part of a bigger code.
What happens is that if -- ActiveCell.Value -- doesnt exist in the
ange --- ThisWorkbook.Sheets(lookingupsheetname).Range("i2:i" &
RownumberofLastBaseattribute) -- then I get an error saying
-- Run-time error 1004 unable to get the match property of the worksheet
function class. This happens EVEN AFTER I added an -- On error go to
errorreading: -- but somehow it doesnt work.
(What I wanted is that if there is an error then in the Activecell a comment
is added giving some warning.)
a) Why is my On Error not go to not working?
b) Also, how to specify in the code that Error handler is supposed to add
only a comment and after that the normal code execution should resume ?
Please guide me.
Sub MainActualUpcodes()
Dim NameOfOSWorkbook As String
Dim sh As Worksheet
Dim r As Integer
Dim opi As Integer
Dim lookingupsheetname As String
Dim RownumberofLastBaseattribute As Integer
Dim vlookuprowthroughMatch As String
NameOfOSWorkbook = "Open end data (OS).xls"
Application.ScreenUpdating = False
Workbooks(NameOfOSWorkbook).Activate
For Each sh In Workbooks(NameOfOSWorkbook).Worksheets
Worksheets(sh.Name).Activate
r = Range("A65536").End(xlUp).Row
opi = ThisWorkbook.Worksheets("Input Sheet").Range("M65536").End(xlUp).Row
lookingupsheetname = WorksheetFunction.VLookup(sh.Name,
ThisWorkbook.Worksheets("Input Sheet").Range("m7:n" & opi), 2, False)
RownumberofLastBaseattribute =
ThisWorkbook.Sheets(lookingupsheetname).Range("i65536").End(xlUp).Row
On error go to Errorreading:
vlookuprowthroughMatch = WorksheetFunction.Match(ActiveCell.Value,
ThisWorkbook.Sheets(lookingupsheetname).Range("i2:i" &
RownumberofLastBaseattribute), 0)
' some code
'
ErrorReading:
With ActiveCell.AddComment
.Visible = True
.Text Text:="Warning:" & Chr(10) & "The mentioned attribute
doesnt exist in the Base Upcode List " _
& Chr(10) & "Update the Base list and re-run the macro"
End With
'some code
'some code
Next sh
End sub
Thanks a lot,
Hari
India