Dim GroupChoice, MEGChoice, StudentName, group1Late, MEG1Late As String
'Making the link variables equal to the cell link for the combo boxes
GroupLink = Range("LateGroup")
MEGlink = Range("LateMEG")
'loop to find which choice the user has picked for their group
If GroupLink = 1 Then
MsgBox "You have not selected a group", vbOKOnly
Exit Sub
Else
If GroupLink = 2 Then
GroupChoice = "1"
Else
If GroupLink = 3 Then
GroupChoice = "2"
End If
'loop to find which choice the user has picked for their MEG
If MEGlink = 1 Then
MsgBox "you have not selected a MEG for the new student", vbOKOnly
Else
If MEGlink = 2 Then
MEGChoice = "A"
Else
If MEGlink = 3 Then
MEGChoice = "B"
Else
If MEGlink = 4 Then
MEGChoice = "C"
Else
If MEGlink = 5 Then
MEGChoice = "D"
Else
If MEGlink = 6 Then
MEGChoice = "E"
End If
StudentName = Range("Studentname")
Sheets("unit 1").Select
If GroupChoice = 1 Then
For row = 1 To 15
group1Late = "A" & row
MEG1Late = "AD" & row
If ActiveSheet.Cells(row, 1).Value = "" Then
Range("group1Late") = StudentName
Range("MEG1Late") = MEGChoice
End
Next
End
End Sub
Run Code Online (Sandbox Code Playgroud)
这是一个大学项目,我需要宏来运行并检查15中的空白区域(这需要稍后重复),然后需要将MEG和学生名称输入到该单元格中.我遇到的问题是,Next为了For Loop使工作可能不是在正确的地方或IDK的东西.它只是拒绝工作,当我把它们取出并替换它时End,End Sub就变成了block if without end if错误.请帮忙.
对于这个if-without-end问题,如果你使用else if(两个单词),每个人都 if需要相应的end if.您应该使用elseif(一个单词)变体来编码.看看这两者之间的区别:
if a = 1 then if a = 1 then
b = 2 b = 2
else elseif a = 2 then
if a = 2 then b = 1
b = 1 else
else b = 0
b = 0 end if
end if
end if
Run Code Online (Sandbox Code Playgroud)
对于这个next-without-for问题,你应该end if用来关闭你的if陈述,而不仅仅是end你现在拥有的陈述:
If GroupChoice = 1 Then
For row = 1 To 15
group1Late = "A" & row
MEG1Late = "AD" & row
If ActiveSheet.Cells(row, 1).Value = "" Then
Range("group1Late") = StudentName
Range("MEG1Late") = MEGChoice
End If ' <-- HERE '
Next
End If ' <-- AND HERE '
Run Code Online (Sandbox Code Playgroud)
End 本身用于停止程序.
我怀疑的错误是由不均衡性你造成的for-next,并if-end if,VB是看到他们交错,因为没有end if那么它假定谈到某处后的next.