Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
545 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | AI (Artificial Intelligence) (21 exercises) |
Topic ==> | Coding - VBA (3 exercises) |
Level ==> | Relatively easy |
Subject ==> | Artificial Intelligence training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
The workbook in the above folder contains a list of boxes for a house move:
We want to be able to see the contents of any numbered box.
Get ChatGPT (or any other AI tool) to create a simple VBA macro which will:
Display an input box asking you to type in a box number.
If this is a number between 1 and 50 the macro will display the contents of the box from column C and the room it should be taken to from column B.
Otherwise, the macro should display an error message.
Time now to test out your macro:
Press Alt + F11 to go into the Visual Basic code editor.
If you can't see the Project Explorer window on the left, press Ctrl + R to show it.
Right-click on this and insert a module.
Paste in the code from your AI tool.
Adjust the name of any worksheet referenced (it's likely you'll have to change Sheet1 to Boxes at this point).
Try running your macro to see if it works!
You should see something like this:
You can type in any box number between 1 and 50.
When you choose OK you should see the contents of this box:
Note that in this case ChatGPT is one row out - this is box 36 it's talking about.
If your macro isn't giving the right result, ask ChatGPT (or whatever AI tool you're using) to correct it, using a prompt similar to this one:
"Please check this gives the right box contents - I think you are one row out."
Check that your revised macro works correctly, then see if you can understand what it's doing! Here's the version Wise Owl got from the exercise:
Sub FindBoxInfo()
Dim boxNumber As String
Dim rowNum As Integer
' Prompt user to enter a box number
boxNumber = InputBox("Enter a box number (1-50):")
' Convert the input into an integer and check if it's within the valid range
If IsNumeric(boxNumber) Then
rowNum = CInt(boxNumber)
If rowNum >= 1 And rowNum <= 50 Then
' Since rowNum is the box number and corresponds directly to rows assuming no header,
' add 1 to account for a header row if present.
' Adjust for header row
rowNum = rowNum + 1
' Display the room and contents of the box
MsgBox "Box #" & rowNum - 1 & " should be taken to the " & Cells(rowNum, 2).Value & _
". Contents: " & Cells(rowNum, 3).Value
Else
' Display error message if the box number is not within the valid range
MsgBox "Error: Please enter a valid box number between 1 and 50."
End If
Else
' Display error message if the input is not a number
MsgBox "Error: Please enter a numeric value."
End If
End Sub
Who needs to learn VBA?
Sadly, the answer is probably ... you do. This was quite a simple macro (and a simple error), but sooner or later there will come a time when you have to link macros together or track down more subtle errors: and for that, you'll need to know how to program in VBA.
You can find other training resources for the subject of this exercise here:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.