需要帮助做这件事:
答案 0 :(得分:1)
嗯...
Sub HomeworkForNmHomie13()
Dim Response, Index, L1, L2, Answer
Do
Response = InputBox("Enter a number from 1 to " & Worksheets.Count)
If Response = "" Then Exit Sub
'Your teacher said don't do error handling, but that's for failures.
On Error Resume Next
Index = Int(Response)
On Error GoTo 0
If Index > Worksheets.Count Or Index < 1 Then
MsgBox ("Your entry was invalid. Please enter a number between 1 and " & Worksheets.Count)
End If
Loop While Index > Worksheets.Count Or Index < 1
Sheets(Index).Activate
L1 = Cells(Rows.Count, "A").End(xlUp).Row 'Assuming an "item" includes blank cells
L2 = Cells(Rows.Count, "B").End(xlUp).Row 'Just grab the last row with data
'Use 2 IIF Statements to check the length using one line of code and look smart as hell
Answer = IIf(L1 > L2, "List 1 is longer", IIf(L2 > L1, "List 2 is Longer", "Same length"))
MsgBox (Answer)
End Sub
如果你愿意&#34;留下深刻印象&#34;你的老师满足最低要求:
Sub LazyHomeworkForNmHomie13()
Index = Int(InputBox("Enter a number from 1 to " & Worksheets.Count))
Sheets(Index).Activate
L1 = Cells(Rows.Count, "A").End(xlUp).Row
L2 = Cells(Rows.Count, "B").End(xlUp).Row
Answer = IIf(L1 > L2, "List 1 is longer", IIf(L2 > L1, "List 2 is Longer", "Same length"))
MsgBox (Answer)
End Sub