If ElseIf and Else statements to call several subs

markswjh

New Member
Joined
Aug 31, 2020
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hi All

I am attempting to create a sub to perform one task if a cell contains a "Y" another if "N" and another if "". If it contains anything else it should call another sub.

I have the following code, but keep coming up with the same "else without if" error. I am a bit of an amateur, so any advice with my code would be great as well, but it would be really useful to be able to fix this error. Thanks

Will

VBA Code:
Sub HWDataEntry()

'
' Homework Data Entry Macro
' This macro loops taking marks, adds them to the
' Homework sheet. Those who haven't submitted are
' added to the detentions list and any data that
' does not meet the value criteria is queried via
' message box
'
Dim usrinput As String
Dim iresponse As Integer
Dim answerinp As String

Sheets("Homework").Select
Range("B4").Select
Sheets("Submition Forms").Select
Range("C4").Select

Do

If ActiveCell.Value = "Y" Then
    ActiveCell.Copy
    Sheets("Homework").Select
    ActiveCell.Select
    Selection.PasteSpecial
    ActiveCell.Offset(1, 0).Select
    Sheets("Submition Forms").Select
    ActiveCell.Offset(1, 0).Select

ElseIf ActiveCell.Value = "N" Then
    ActiveCell.Copy
    Sheets("Homework").Select
    ActiveCell.Select
    Selection.PasteSpecial
    ActiveCell.Offset(1, 0).Select
    Sheets("Submition Forms").Select
    ActiveCell.Offset(1, 0).Select
    Call FmtDetentions
    Call DetentionListAddName

ElseIf ActiveCell.Value = "" Then
    End If
  
Else
    Call CorrectData
End If

Loop Until IsEmpty(ActiveCell)
    
 Sheets("Homework").Select
 Cells.Select
    Range("F3").Activate
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent1
        .TintAndShade = 0.799981688894314
        .PatternTintAndShade = 0
    End With

End Sub
 
rather oddly having the loop not work properly previously it is now exiting when it should. I think it may have been the machine rather than the code that was causing the issue. Sorry!

It is now exiting when it is blank from the first set of code you sent which it wasn't previously, and it now runs the call CorrectData when it should. I have no idea why
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top