Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7623335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:40:52+00:00 2026-05-31T04:40:52+00:00

I am iterating through rows,and looking up the first column of each row(name) using

  • 0

I am iterating through rows,and looking up the first column of each row(name) using a different function for finding his marks.

For each “name” there is a particular entry in a different table(“marks”) which can also be blank or “-“

Sub main()
On error goto errorhandler
Dim name as string
Dim marks as double
Dim source as range
Dim runs as integer

runs = 1
Set source = Sheets("input").Range("$A$2")
i=1

Do until source.offset(i,0) = ""        'iterate through rows 

    name = source.offset(i,0)
    marks = find(name)

    do until runs * marks > 100
        runs = runs + 1 'since marks is not defined;runs overflows 
    Loop
    'a lot of code which relies on marks
errorhandler:
    i = i + 1
Loop

End Sub

Function find(name as string) as double
    find = application.vlookup(name,Sheets("values").Range("$A$2,$C$5"),2,0)
End function

now as i said the value in column 2 of that table can also be blank or “-” and thus results in error Runtime error 13 “Type mismatch”

i even tried putting on error statement inside the loop
VBA should normally search for error handling in the calling function i.e “main” but its not doing so

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:40:54+00:00Added an answer on May 31, 2026 at 4:40 am

    Add an Err.Clear after errorhandler:

    Also, see the Excel help on Err.Clear which reccomends On Error Resume Next
    together with If Err.Number <> 0 Then

    This will produce much clearer code

    Something like

    Sub main()
        On Error Resume Next
        Dim name As String
        Dim marks As Double
        Dim source As Range
    
        Set source = Sheets("input").Range("$A$2")
        i = 1
    
        Do Until source.Offset(i, 0) = ""       'iterate through rows
            name = source.Offset(i, 0)
            marks = Find(name)
            If Err.Number <> 0 Then
                Err.Clear
            Else
                ' Your other code for non-error case here
    
            End If
            i = i + 1
        Loop
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am iterating through a file and on each line I am looking for
Is iterating through the vector using an iterator and copying to a list the
I'm using KVC to iterating through a few views. Having trouble setting BOOL properties:
Say i am having set of rows in a table and each row is
For Each row As DataGridViewRow In DGV.Rows DGV.Rows.RemoveAt(CInt(row.Index.ToString)) Next The above code will remove
I need to fetch a number of rows between two column values, using a
When iterating through a set of assemblies, e.g. AppDomain.CurrentDomain.GetAssemblies(), dynamic assemblies will throw a
I'm iterating through a HashMap (see my earlier question for more detail) and building
I'm iterating through some objects and trying to set some properties that, apparently, don't
Duplicate Modifying A Collection While Iterating Through It Has anyone a nice pattern to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.