Limit number of elements/values in a dynamic range

Eric Carolus

Board Regular
Joined
Sep 17, 2012
Messages
133
Office Version
  1. 2016
Platform
  1. Windows
Hi folks

I have a dynamic range called Teachers on sheet 1.
I wish to add teachers' initials to that dynamic range, but I wish to limit the
number of teacher initials to, say 20 teachers only.

I have downloaded the following code (for a button) [thanks to the original author ] and it works well for a button.
I wish to tweak the code so that, if I add directly to the range called Teachers, no
teachers should be accepted to/in that dynamic range.

VBA Code:
Private Sub CommandButton1_Click()

If addRng Is Nothing Then
    Set addRng = Range("C5")
Else
    Set addRng = addRng.Offset(1, 0)
    If addRng.Row > 16 Then
        'You may also want to unload the form, or use a message box
        ' to tell the user what is happening here
        Set addRng = Nothing
        Exit Sub
    End If
End If

addRng.Value = Me.TextBox1.Value
End Sub

I will apreciate any and all help.

Thanks
Crow
 
Last edited by a moderator:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Not sure but you want to run code and count the used rows in a range but only if the edited cell is in a named range? Perhaps

 
Upvote 0
Hi Micron

This is not quite what I was looking for.
The idea is to allow on specified number of elements/values to the named range.
Once the specified number of element/values had been added to the named range,
it should not be possible add more values to the named range.

Is this even possible?

Crow
 
Upvote 0
IIRC, I meant that as a starting point because you only care about whether or not someone is trying to add/edit within a specific range.

I'm a bit confused though. You said you had code that works from a button click and I provided a link on how to use the update of a range instead so it seems strange that you're asking if what you want to do is possible. :unsure:
Would you not just need to check if the range is being updated with

If Not Application.Intersect(Target, Range("YourRangeNameHere")) Is Nothing Then

and having inserted the code you say works, let that run?
 
Upvote 0
Hi Micron
I have tried my utmost but I simply cannot make it work.
Thanks you for your help anyway.
Crow
 
Upvote 0
If you specify where the range of 20 cells is I'll try to work out something.
 
Upvote 0

Forum statistics

Threads
1,215,641
Messages
6,125,986
Members
449,276
Latest member
surendra75

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