EXCEL VBA - BASICS VIDEOS
- Excel VBA Part 1 - The VB Editor
- Excel VBA Part 2 - Writing Your First Macro
- Excel VBA Part 3 - What To Do When Things Go Wrong
- Excel VBA Part 4 - Buttons, Toolbars and Keyboard Shortcuts
- Excel VBA Part 5 - Selecting Cells
- Excel VBA Part 6 - Worksheets, Charts and Sheets
- Excel VBA Part 7 - Working with Workbooks
- Excel VBA Part 8 - Variables in VBA
- Excel VBA Part 9 - Object Variables
- Excel VBA Part 10 - Message Boxes
- Excel VBA Part 11 - Input Boxes
- Excel VBA Part 11a - Application.InputBox
- Excel VBA Part 12 - With Statements
- Excel VBA Part 13.1 - If Statements in VBA
- Excel VBA Part 14.1- Select Case Statements
- Excel VBA Part 15.1 - Do Until and Do While Loops
- Excel VBA Part 16 - For Next Loops
- Excel VBA Part 17 - For Each Loops
- Excel VBA Part 18 - Creating Functions
- Excel VBA Part 19 - Error Handling
- Excel VBA Part 20 - Event Procedures
- Excel VBA Part 21 - User Forms
Excel VBA - Basics videos | Excel VBA Part 11a - Application.InputBox
Posted by Andrew Gould on 03 November 2014
If you've used the generic InputBox function in VBA you may be frustrated by its limitations. This video shows you how to use the far superior Application.InputBox method. You'll learn how to specify the data type returned by the InputBox and how to use its built-in validation feature to control what users can enter. The video also covers how to return a simple formula and a more complex function from the InputBox and also how to allow users to select a range of cells which can then be referenced by your VBA code. The final part of the video covers a more complex example in which the InputBox returns an array of values which can be looped over and manipulated in various ways.
You can download any files that you need to follow the video here.
You can increase the size of the video:
You can view the video in full screen mode as shown on the left, using the icon at the bottom right of the frame.
You can also increase the quality of the video:
You can improve the resolution of the video using another icon at the bottom right of the frame. This will slow down the connection speed, but increase the display and sound quality. This icon only becomes visible when you start playing the video.
Finally, if nothing happens when you play the video, check that you're not using IE in compatibility view.
In this video, you mentioned the singular is usually the object in the collection, eg worksheet is an object of the collection of worksheets (plural).
You mentioned usually.
What are the exceptions?
The most notable one, I think, is Range. A range can be a single cell as well as a collection of other cells.
Using the For Each loop to process a range works differently. In most cases, to process a collection with a For Each loop, you declare a variable whose type is the singular object, e.g. Dim c As Chart. You then use the plural name of the collection in the loop, e.g. For Each c in Charts. The relationship holds true for most examples - Worksheet:Worksheets, Workbook:Workbooks, Shape:Shapes, PivotTable:PivotTables, etc.
To process a range with a For Each loop, you would use the singular object to declare the variable, e.g. Dim r As Range. You would not, however, use Ranges as the name of the collection. Instead, you must specify the range of cells you wish to loop over. This provides a large amount of flexibility, as many properties and methods return a reference to a range object. Any of the examples below are valid:
For Each r In Range("A1:A10")
For Each r In Range("A1").CurrentRegion
For Each r In ActiveSheet.Cells
For Each r In Selection
One thing I noticed from watching your collections video is this. Normally to loop over a collection, you define a variable of the same type as the collection. For example:
Dim ws as Worksheet
For Each ws In ThisWorkbook.Worksheets
So assuming that's a "rule" I tried this, which obviously failed:
Dim MyColl As Collection
Dim MyCollElement As Collection
For Each MyCollElement In MyColl
thinkg that since I'm looping over a collection (MyColl), I must define a variable of the same type, MyCollElement, as a Collection too!
Hi, I have created a custom ribbon and attached a macro to this item in excel. My question is how do I make this custom ribbon/button available on each end user's terminal? The macro-enabled document is located on a shared folder through which all users have equal access. However, the custom ribbon/button is not available to all users when opening the same workbook.
Can you kindly help or instruct accordingly please?
Hi, you can share your custom ribbon configuration with other users as described here.
I hope that helps!
Thanks for the quick response.
I am aware of the importation method but I was wondering if there was anything more versatile and dynamic. The end product would target many users on various terminals and it would be inefficient to have everyone import custom tools everytime a change, improvement or alteration is made .
Is it possible to have implicitly included in the code the ability to have real time updates for the custom toolbar or ribbon?
Thanks a lot for your help.
Hi, I think that the bottom answer on this page may help!
Hai Andrew G,
I just want to encrypt my VBA code. Apart from using password protection from tools menu, Is there any possible way to do that? If the user tries to open tne module then the code should be at an encrypted state. I do not think, using password is an effective way to protect my code because there is a way to break the password and to view the code.
Hi Abishek, there are commercial tools available such as http://www.lockxls.com/product.asp and https://www.ozgrid.com/excel-add-ins/encrypt-VBA.htm
I haven't used either of them so can't comment on their effectiveness.
I hope that helps!
Hai Andrew G,
Thankyou so much for your help. Is there any alternative ways to use firefox as a web browser in Excel VBA instead of IE. If any tutorial available for this case, kindly give me that link.
Hai Andrew G,
Firstly, I would like to thankyou for this woderfull playlist of ExcelVBA. I have a request for you. Is it possible to view the progress status of the ongoing Macro through a status window. It should show the status as percentage.
The VBE doesn't have a feature like the one you've described. You could create your own progress indicator with a User Form and Progress Bar as shown in this video https://www.wiseowl.co.uk/videos/excelvbauserforms/progress-bar.htm
I hope that helps!
Hai Andrew G,
Thanks Andrew that helps.... Also i have a lot of doubts in using selenium for webpage scraping. Currently i have installed SeleniumBasic-18.104.22.168 in my Windows 10 device. for example
Dim SLNM As New WebDriver
SLNM.Start "firefox", "http://www.google.com"
The above code only opens a new firefox window but the URL is not getting loaded. Please help me with this issue.
Hi Abishek, I'm sorry but I don't have any experience with using Selenium so I can't help you with this.
I have gone through your vba videos and they all were awesome. i have one request if you can create one more video that shows dynamic auto filter. .
First of all I would like to congratulate you for this incredible series of videos about VBA.
Through you, I have been able to improve and learn more and more my knowledge in Excel and VBA.
I would like to know if you are going to, or intend to release, any video about Regular Expressions (RegExp) for Excel / VBA?
It is a very interesting and very powerful subject for queries, validations, ect. But little used or demonstrated by the communities.
Again, thank you for the dedication and high quality of your teaching.
A hug from Brazil!
That's the second question on Regular Expressions I've had this week! The topic has been on my list for some time, I simply haven't had time to plan and create a video on the subject yet. Perhaps I should move this topic a little further up the list and aim to create something in the near future.
Thank you for the kind comments and for watching!
I'm developing an Excel VBA program, but I'm having a problem. I need to download a Captcha image from this site.
I have a workbook with 4 sheets. Three of these sheets have employees that are scheduled daily, the fourth is the actual schedule. What I would like to accomplish is when I schedule that person he or she is highlighted on the other sheets to help identify who we can and cannot use. I am fairly new to VBA, but extremely excited to learn something new. Thank you so much for you time and any assistance woould be greatly appreciated.
The question is a bit vague, and I suspect this answer won't help much. What I'd do is follow through the videos or blogs on our website for now.
However, here's a macro to colour in all the cells in range A1:A3 which contain the name Bill. You could obviously modify this to work with any range and any name.
Dim PersonCell As Range
Dim PersonRange As Range
'set a variable to refer to the range where people can be found
Set PersonRange = Range("A1:A3")
'colour in all the people with the right name
For Each PersonCell In PersonRange.Cells
If PersonCell.Value = "Bob" Then
PersonCell.Interior.Color = vbGreen
Exactly when and how you'd call this macro would depend on exactly what you were trying to achieve.