VBA Userform to generate next available number

NaumanJ

New Member
Joined
Mar 17, 2020
Messages
18
Office Version
  1. 2016
Platform
  1. Windows
Hi there,

I am trying to create a userform that will present me with the next available phone number (based on Switch type). Once the phone number is generated, and the user confirms they will be using it, the number's status will go from inactive to active.

Here's a mock of how the raw data looks like:

Switch TypePhone NumberActivity
19050000001Active
19050000002Inactive
19050000003Inactive
29050000004Active
29050000005Active
29050000006Inactive
39050000007Inactive
39050000008Inactive
39050000009Inactive
49050000010Active
49050000011Active
49050000012Inactive
59050000013Inactive
59050000014Active
59050000015Inactive

Here's a mock of how the userform will look:
1591365456799.png



This is the flow I'm looking for:
  1. User selects the switch type they're looking for (from 1 to 5)
  2. User specifies whether they want an Active or Inactive number (The user will always select "inactive" number, but I have this here to show that the phone generator requires two criteria. I can remove from userform if it's possible to account for it in the code)
  3. After they've specified what they want, they will click "Generate Phone Number"
  4. The phone number will show in the textbox below "Here's your phone number"
  5. If the user says "yes" or "no" to "confirm if they will be using this phone number", it will either change the Activity of the phone number to "Active" (if Yes), or leave it the same as "Inactive" (if No)
Any help is greatly appreciated with this. Please let me know if you require any more information - thank you so much :)!!
 

Attachments

  • 1591365194698.png
    1591365194698.png
    25.8 KB · Views: 7

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Because any macro will need to refer to the names of the objects used in the user form, it would be easier to see that information if you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Include a detailed explanation of what you would like to do referring to specific cells, rows, columns and worksheets. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
Because any macro will need to refer to the names of the objects used in the user form, it would be easier to see that information if you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Include a detailed explanation of what you would like to do referring to specific cells, rows, columns and worksheets. If the workbook contains confidential information, you could replace it with generic data.

Awesome recommendations - thanks! I've uploaded the file on Dropbox (ready to be edited): Phone Number Generator.xlsm

I have three sheets in the file:
1) The actual userform (you can see that it's designed, it just doesn't have any code to make it function right now)
2) Mock data (listing of phone numbers and their respective activity)
3) Labels (to identify the 5 switch types and 2 activity options)

This is the flow I'm looking for:
  1. User selects the switch type they're looking for (from 1 to 5)
  2. User specifies whether they want an Active or Inactive number (The user will always select "inactive" number, but I have this here to show that the phone generator requires two criteria. I can remove this from the userform if it's possible to account for it in the code)
  3. After they've specified what they want, they will click "Generate Phone Number"
  4. The phone number will show in the textbox below "Here's your phone number"
  5. If the user says "yes" or "no" to "confirm if they will be using this phone number", it will either change the Activity of the phone number to "Active" (if Yes), or leave it the same as "Inactive" (if No)
Literally any help will be greatly appreciated - thanks a million :) !!
 
Upvote 0
You are an absolute gem - thank you so so much!!!

Stay safe and have an amazing day :)
 
Upvote 0
You are very welcome. :)
 
Upvote 0
You are very welcome. :)

Hey Mumps,

Thanks so much for helping me with this :) I need to make some changes to add one more component, but I've been really struggling with this for the past few days. If you have some free time, I was wondering if you can help me with this? It'd be greatly appreciated, but you've already done so much, so I understand if you don't want to.

Here's what I'm trying to do:

It's the same userform, except now, I'm trying to add an option for "specify amount of numbers required", as team members can request multiple numbers (sometimes 50+) at one time, so it's tedious for them to keep generating numbers one by one.

I've updated the form to reflect how it should look - I just haven't been able to make it functionally work after a lot of trial-and-error.

This is how the flow would look:

1. User selects the switch type they're looking for (from 1 to 5)
2. User specifies the amount of numbers they need (FYI - all the numbers would be for the same switch. So if they selected Switch 1, it would only be for that switch, and not a combination of switches)
3. After they've specified what they want, they will click "Generate Phone Number"
4. The phone numbers will show in the main "PN Generator" sheet, starting from Cell (A10), pasting downwards for the numbers specified
5. If possible, but not a requirement, it they state they want more numbers than their are available, it will open a message box saying "you have selected too many numbers, please lower your selection" or something along those lines (of course it'd be great if it can tell the number of available numbers for that switch, but that sounds too complex)
5. If the user says "yes" or "no" to "confirm if they will be using this phone numbers", it will either change the Activity of the phone number to "Active" (if Yes), or leave it the same as "Inactive" (if No)

This is the link to the older file: Old Phone Generator.xlsm
This is the link to the newer file: New Phone Generator.xlsm

This has been driving me nuts so I would really really appreciate any help. Thank you so much in advance :)
 
Upvote 0
Click here to download your file. I've had to unmerge two merged ranges and formatted them as "CenterAcrossSelection" to give the same effect as merging. You should avoid using merged cells as they almost always cause problems for macros. Since there was a possibility that a user might choose more phone numbers than were available as "Active" for any given switch type, I have incorporated a warning if this happens that asks the user to select a smaller number.
 
Upvote 0
Click here to download your file. I've had to unmerge two merged ranges and formatted them as "CenterAcrossSelection" to give the same effect as merging. You should avoid using merged cells as they almost always cause problems for macros. Since there was a possibility that a user might choose more phone numbers than were available as "Active" for any given switch type, I have incorporated a warning if this happens that asks the user to select a smaller number.

Mumps - you are an angel!!! I can't thank you enough - you are awesome. Sending you good wishes :)!!
 
Upvote 0

Forum statistics

Threads
1,214,548
Messages
6,120,141
Members
448,948
Latest member
spamiki

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