Preventing number over 100 and limiting combobox to list

litestream

Active Member
Joined
Jul 24, 2006
Messages
323
I'd like to prevent people entering a number over 100 in cell C10 of my worksheet. I found the following from Erik on the boards but it wouldn't work - maybe I should put it somewhere different to the worksheet module?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Const limit = 100
Set rng = Range("C10")
If Target.Count > 1 Then Exit Sub
With Application
.EnableEvents = False
If Len(Target) > limit Then .Undo
.EnableEvents = True
End With
End Sub

Also, I have a combobox with the following code:

Code:
Private Sub Workbook_Open()
Dim i As Integer
With Sheets("Data")
   With .ComboBox1
       .AddItem "Standard"
       .AddItem "Euro"
   End With
   With .ComboBox2
       For i = 1 To 7
          .AddItem i
       Next
   End With
End With
End Sub

Is there a way to prevent people entering numbers other than 1 to 7?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

sheetcode
that code was to prevent the users from entering more than 100 characters in C10, hence LEN !
you need
Code:
If Target > limit Then .Undo

combobo
see properties: STYLE
you need fmStyleDropDownList

kind regards,
Erik
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
you're WELCOME !!

checking again this one ...
you could use validation for all this (validate cell C10 and replacing comboboxes by another validated cell)
 

Forum statistics

Threads
1,136,647
Messages
5,676,983
Members
419,667
Latest member
MegEri

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
Top