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 9052093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:04:54+00:00 2026-06-16T13:04:54+00:00

I keep getting a compile error: next without For when I try to run

  • 0

I keep getting a “compile error: next without For” when I try to run this code. However, after checking everything over multiple times, I do not see how it does not recognize their presences. This is my first VBA code, so any help would be greatly appreciated.

Sub Naming()
'
' Naming Macro
' Assigns a category name in a cell based on values in a cell one column over 
'

Dim number As Double

For i = 9 To 200
    number = Cells(i, 3).Value
        If number = 0 Then
            GoTo Line1
        Else
            If number <= 199999 And number > 0 Then
            Cells(i, 2) = "EP-GEARING"
        Else    
            If number <= 399999 And number > 199999 Then
            Cells(i, 2) = "DRIVES"
        Else
            If number <= 499999 And number > 399999 Then
            Cells(i, 2) = "FLOW"
        Else
            If number <= 599999 And number > 499999 Then
            Cells(i, 2) = "SPARES"
        Else
            If number <= 699999 And number > 599999 Then
            Cells(i, 2) = "REPAIR"
        Else
            If number <= 799999 And number > 699999 Then
            Cells(i, 2) = "FS"
        Else
            If number <= 899999 Then
            Cells(i, 2) = "GC-GEARING"
        Else
            GoTo Line1
Line1:
        End If
Next i

End Sub
  • 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-06-16T13:04:55+00:00Added an answer on June 16, 2026 at 1:04 pm

    ElseIf is one word in VB.

    If number = 0 Then
        'Do nothing
    ElseIf number <= 199999 And number > 0 Then
        Cells(i, 2) = "EP-GEARING"
    ElseIf number <= 399999 And number > 199999 Then
        ...
    Else
        'Do nothing
    End If
    

    However, Select Case would fit better here:

    Select Case number
        Case 0
            'Do nothing
        Case 1 To 199999
            Cells(i, 2) = "EP-GEARING"
        Case 200000 To 399999
            ...
        Case Else
            'Do nothing
    End Select
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error when I try to compile my code : cc
I keep getting this error when I compile and run my Java program using
So I keep getting this error when trying to compile C++ code using CodeBlocks.
When I run the following code, I keep getting this error: Traceback (most recent
When I try to compile my erlang script I keep getting this error: (master@WN7-18TL6M1.amer.dell.com)15>
With the following code, I keep getting error C2535 when I compile. It's complaining
Keep getting this error after inserting a subdatasheet into a query and trying to
As the title says, keep getting this error when trying to compile. From Googling
I keep getting this error compile error /Users/dean/src/carolian/app/views/layouts/events.html.erb:10: syntax error, unexpected ',', expecting ')'
I keep getting this error trying to run the debugger: Program received signal EXC_BAD_ACCESS,

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.