USING VBA EXCEL AND OPTION EXPLICIT Write a program to tell whether a person is
ID: 3810948 • Letter: U
Question
USING VBA EXCEL AND OPTION EXPLICIT
Write a program to tell whether a person is a Beatle. Here’s the worksheet:
The user types a name in B1, and clicks the button. If the name if John, Paul, George, or Ringo, the program says that the person is a Beatle:
Otherwise, the program shows “Not a Beatle.”
The program should work for upper- and lowercase characters, and when there are spaces before and/or after the name. For example, “ jOHn “ should be identified as a Beatle.
The usual coding standards apply.
1 First name: 3 Is that a Beatle? George RunExplanation / Answer
Hi,
Please find below the VBA code for your requirement. Please paste this code into sheet2 macro page of your excel workbook.
VBA Code-
Private Sub CommandButton1_Click()
Dim Name As String
Name = Worksheets("Sheet2").Cells(1, 2).Text
If Trim((UCase(Name)) = UCase("John") Or Trim(UCase(Name)) = UCase("Paul") Or Trim(UCase(Name)) = UCase("George") Or Trim(UCase(Name)) = UCase("Ringo")) Then
Worksheets("Sheet2").Cells(3, 2).Value = "Thats a Beatle"
else
Worksheets("Sheet2").Cells(3, 2).Value = "Not a Beatle"
End If
End Sub
Regards,
Vinay Singh
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.