Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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("i65 536").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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Error Handling #N/A with AVERAGE Function - Average of values in Row | Excel Worksheet Functions | |||
Match function, N/A error, how do I get around it? | Excel Programming | |||
Error Handling Open Function or query for missing Files | Excel Programming | |||
Error Handling | Excel Programming | |||
Error handling in vba function | Excel Programming |