Forum Discussion
TSmith98
Apr 30, 2021Copper Contributor
VBA Loop Code
Hello, I am a student struggling with some coding, I'm trying to run a loop inside of a loop so that the first loop goes down and the second goes across. Can someone please help me fix it? ...
- Apr 30, 2021
Is this better? Please check carefully.
HansVogelaar
Apr 30, 2021MVP
What is the problem you're having with the code?
It might help if you attached a copy of the workbook (without sensitive information) - it is hard to follow what the code does without seeing what it operates on.
TSmith98
Apr 30, 2021Copper Contributor
Hello,
I have attached the file
I have attached the file
- HansVogelaarApr 30, 2021MVP
I would change
For i = 2 To MCLastRow If Cells(i, 2).Value = "SBUB10" Then 'Code not recognising this 'Change to ending with 10 ErrorLogWS.Range("c" & i).Value = 40 ErrorLogWS.Range("D" & i).Value = 30 ElseIf Cells(i, 2).Value = "SBUB20" Or Cells(i, 2).Value = "SBUB30" Then ErrorLogWS.Range("c" & i).Value = 30 ErrorLogWS.Range("D" & i).Value = 40 Else End If Next ito
For i = 2 To MCLastRow Select Case ErrorLogWS.Cells(i, 2).Value Case "SBUB10" 'Code not recognising this 'Change to ending with 10 ErrorLogWS.Range("c" & i).Value = 40 ErrorLogWS.Range("D" & i).Value = 30 Case "SBUB20", "SBUB30" ErrorLogWS.Range("c" & i).Value = 30 ErrorLogWS.Range("D" & i).Value = 40 End Select Next iThis makes Cells(i, 2) explicitly refer to ErrorLogWS.
If the code still doesn't want what you do, please provide detailed information about the problem.
- TSmith98Apr 30, 2021Copper ContributorHey,
Thank you for this, but that part is working.
It is the section after that part that starts with:
''Code to find each semester and total credits'''
where there are two do loops- HansVogelaarApr 30, 2021MVP
And what exactly is the problem there?