Limiting the input length in an Input Box

JBShandrew

Board Regular
Joined
Apr 17, 2011
Messages
54
Hi everyone,

Thank you all for the help you give me, to help me learn VBA. I am recreating an electronic form in VBA that was done in Excel with just formuls, and have incorporated input boxes in a few fields, that need to be filled out.

Now I need to limit the characters that can be entered in to the Input Box to 20 characters due to the limit of the width of the form.

This is what I have, and thanks to answers to my questions, is working very well.

.Range("$G$57").Value = StrConv(InputBox("Enter Your Title", _
" Field Inspector's Name", "Field Inspector" , 925, 11000), vbProperCase)


Can I add something in this line of code to limit the character length? If not, can you kindly show me how?

Thank you in Advance.

Sincerely,

J.B.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Why don't you use Data Validation instead? It's native and there's an option to set a fixed length.
 
Upvote 0
It can, but why bother? You're already feeding the input box's results back to a cell:

Range("$G$57").Value

So just use Data Validation instead.
 
Upvote 0
It can, but why bother? You're already feeding the input box's results back to a cell:

Range("$G$57").Value

So just use Data Validation instead.


As I discovered in one of my excel classes using data validation can be erased if other values are copied and pasted in to a cell, which is why I am trying to learn how to do this in VBA to preserve the code from accidental deletion.

I have a long, long way to go, but I want to get to the point that I do everything in VBA.
 
Upvote 0
As I discovered in one of my excel classes using data validation can be erased if other values are copied and pasted in to a cell, which is why I am trying to learn how to do this in VBA to preserve the code from accidental deletion.

I have a long, long way to go, but I want to get to the point that I do everything in VBA.

Yes, that's true. But be careful about depending too much on VBA when a native solution can suffice. VBA is not a be-all-end-all solution, and it can just as easily be broken (all you need to do is disable macros). By the same token people often try to get a native solution to take place of something that can only be done via VBA.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top