Avatar of Pedro
Pedro
 asked on

Create combinations in renamed sheets for specific groups only

The code makes combinations from data in B10:AG19 in "sheet1" and puts them in sheets "NumbersX" where "X" is 1-10.

When the code is executed again it deletes data in sheets "NumbersX" then writes new data.

The goal here is to edit the code to:


1) Number the sheets using the number in B10:B19. In this instance "Numbers_3, Numbers_4, numbers_7, etc.

2)  write combinations using only the first number (located in B10:B19). After it is finished wit combinations that match the first number stop with that sheet then go to next sheet, etc.

FYI: I have 1) manually edited sheet names to match the desired result and the first sheet shows only combinations with the number 3 that matches the number in B10.

There is no data in the last sheet since there are no numbers in B19:AG19
CreateCominationsFromGoups_2-2020_F.xlsm
VB ScriptMicrosoft OfficeMicrosoft Excel

Avatar of undefined
Last Comment
Pedro

8/22/2022 - Mon
Martin Liss

You didn't upload a workbook.
Pedro

ASKER

Martin,


File uploaded now.


Thanks

Martin Liss

I don't understand why you are attaching a workbook so similar to one of your previous ones, but in this one you only have sheets for Numbers_3, 4, 7, 8, 10, 11, 17, 18, 2 and one named just "Numbers_". It fails as soon as you try to write to the non-existent named "Numbers_1". What do you want me to do here?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Martin Liss

Try changing the error routine to this:

Err_Q_28233532:

  lngErr_Number = Err.Number
  If Err.Number = -2147352565 Or Err.Number = 9 Then
    ThisWorkbook.Worksheets.Add After:=Worksheets(Worksheets.Count)
    ActiveSheet.Name = "Numbers_" & CStr(lngNumbers)
    Resume Next
  End If
  strErr_Description = Err.Description
  
  On Error Resume Next
  
  Application.ScreenUpdating = True
  
  Beep
  
  MsgBox "Error #" & CStr(lngErr_Number) & _
         vbCrLf & vbLf & _
         strErr_Description, _
         vbExclamation Or vbOKOnly, _
         ThisWorkbook.Name
  Resume Exit_Q_28233532
  
End Sub

Open in new window

Pedro

ASKER

Martin,


The goal is to limit the combinations to only those that match the first number in each row at B10:B19 and to name each sheet with that number.


I will attach the original file that works.

Martin Liss

Try this.
29173071.xlsm
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Pedro

ASKER

Martin,


The code does rename pages but it fails to stop when combinations for the first number are complete. 

See picture

Also, it makes a "sheet12" then when run again "sheet11". If these are used during processing they should be deleted as it may cause undesired operation and overhead. (See bottom of picture).


The idea is to slowly build on the current code so I need it as clean and as little overhead as possible.


Martin Liss

I'm sorry that I didn't look far enough down the sheets to see the numbers that don't match the sheet name. I will fix that but fist let me ask you about something else.

The code in the Q_28233532 sub (which is now inappropriately named) always calls the CreateCombinations Sub with 3 parameters. Those 3 parameters are 1) the source of the data, 2) the destination of the sets, and 3) the number of cells in a set. However, in the CreateCombinations Sub there is code that checks to see if those values have been supplied, and if not it prepared to ask for the value(s) via inputbox's. Given how the CreateCombinations is called, those inputbox's aren't necessary and the code associated with them could be eliminated. Do you want me to do that?
Pedro

ASKER

Yes, they can be eliminated as long as it can be eliminated without affecting the outcome.

 I believe it’s part of the original code that asked for 1) the source of the data, 2) the destination of the sets, and 3) the number of cells in a set. 


it’s been automated   to 1) pick from B10:AG19, 2) make new sheets for each set and 3) 5 cells in each set.

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Martin Liss

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Pedro

ASKER

Martin,


Looks like it will work. A bit more testing and I'll know better. I get an error if I use less than 32 numbers in each row, but no worries there. I've corrected that.

The real question is:

since it only makes combinations with one common number, can it handle up 70 numbers ? 

If not 70 then what is the maximum total numbers it can make combinations with?

Martin Liss

can it handle up 70 numbers ?
Give it a try, The worst that can happen is that it crashes or hangs up.
Pedro

ASKER

It does not work with the current macro. There must be some sort of limit. I'll open another question and close this one.


⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.