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

  • SEARCH
  • Home
  • 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 6159935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:12:53+00:00 2026-05-23T21:12:53+00:00

I know there are a ton of questions about constructing looped codes in vBA

  • 0

I know there are a ton of questions about constructing looped codes in vBA already but hopefully this will be a quick answer, i wasn’t able to find a page addressing this issue.

My goal is to check the values from one range with values in another range, and if is a match it will perform a function and display results at the end. However, if the corresponding value in the range is “N/A” I want the results to display immediately and move onto the next checked value. Right now I am obtaining a ‘no for loop’ error for my code and i understand why. But I don’t know how to fix this problem. Can anyone help?

Sub solubility()

Dim coeff As Range, groups As Range
Dim anion As Range
Dim a As Range
Dim nextrow As Long
Dim j As Range

Worksheets("properties").Select
Range("P7:P2000").Select
Selection.ClearContents

'solubility groups range
groups = Worksheets("Solubility").Range("A2:A33")
'group coefficients range
coeff = Worksheets("Solubility").Range("B2:B33")

anion = Worksheets("properties").Range("AB7:AB887")

For Each a In anion
   For Each j In groups
        If UCase(a.Value) = UCase(groups(j).Value) Then
             If groups(j).Value = "" Or "N/A" Then
                Worksheets("properties").Range("P" & a.Row).Value = "N/A"
                Next a
             Else
                anvalue = coeff(j).Value * Range("AC" & a.Row).Value
             End If
        End If
        If UCase(Range("AD" & a.Row).Value) = UCase(groups(j).Value) Then
            cavalue = coeff(j).Value * Worksheets("properties").Range("AE" & a.Row).Value
        If UCase(Range("AF" & a.Row).Value) = UCase(groups(j).Value) Then
            cb1value = coeff(j).Value * Worksheets("properties").Range("AG" & a.Row).Value
        End If
        If UCase(Range("AH" & a.Row).Value) = UCase(groups(j).Value) Then
            cb2value = coeff(j).Value * Worksheets("properties").Range("AI" & a.Row).Value
        End If
   Next j
        If UCase(Range("AD" & a.Row).Value) = UCase("[MIm]") Then
            cavalue = Range("AE" & a.Row) * Worksheets("solubility").Range("B2").Value + Range("AE" & a.Row) * Worksheets("solubility").Range("B7").Value
        End If
    nextrow = Worksheets("properties").Cells(Rows.Count, 15).End(xlUp).Offset(1, 0).Row
    Worksheets("properties").Range("P" & nextrow).Value = _
        anvalue + cavalue + cb1value + cb2value + Worksheets("solubility").Range("b34").Value
Next a
End Sub

I have the line ‘Next a’ twice, and excel doesnt like this, but I want to automatically jump to the next checked value without performing the remaining function if I get the “N/A” value.

  • 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-23T21:12:53+00:00Added an answer on May 23, 2026 at 9:12 pm

    I know this will rile the feathers of some of my purist brethren, but I would actually suggest a judicious use of GoTo in your case:

        For Each a In anion
           For Each j In groups
                If UCase(a.Value) = UCase(groups(j).Value) Then
                     If groups(j).Value = "" Or "N/A" Then
                        Worksheets("properties").Range("P" & a.Row).Value = "N/A"
                        GoTo NextA
                        ....
                     End If
                End If
                ....
           Next j
           ....
    NextA:
        Next a
    

    Overuse of GoTo will quickly turn your code into spaghetti, but in this case I think it is actually the most readable option you have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there have been a ton of questions about the same thing, but
I know there's a ton of similar questions on here but I reviewed a
So, I know there are a ton of related questions on SO, but none
I know there are a lot of questions around on this subject, but I've
I know there is a ton of stuff on this already and have tried
I know there are a ton of questions on here about jquery image carousel,
I know there have been a ton of questions about how to implement automatic
I know there is many questions about CSS inheritance but none of what i
I know there is a lot on this topic but I can't get any
I know there are a lot of similar questions on SF, but I think

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.