Posts by 6StringJazzer

    Your description is very generic so it is not possible to give you code that you can simply plug in.

    Where is the ListBox? What is its name? If on a worksheet, is it ActiveX or Forms?
    Where is the button? What is its name? If on a worksheet, is it ActiveX or Forms?
    What worksheet has the value you want to make active?

    Is that worksheet active when you click the button


    Something like this:


    Your code seems to cover everything except the message. Also you have four mutually exclusive conditions so should not use serial If statements.


    Ciao! Not sure what you mean by "i can't use the same name as the original file + variable part".


    What name are you using now? It looks like you are using the contents of the field "codice" as the file name.

    What name do you want to use instead?

    This code takes the text in the cell as input and returns an array (1 to 4) with name, number, company name and sender's email address.

    UBound will raise an error if the argument is not an array. If the element is a scalar, like a Long or String, that will cause an error.


    I also suggest making the loop constraints dynamic.

    I think you want something like this:


    You have the line commented out to copy the items to the worksheet (line 22). I fixed that and your code ran OK for me.


    However, the problem could be in your data. This code will randomly choose cells in column B until it has found four unique values. If it contains many cells but many duplicate values, it could take some time to find four unique values. If it does not contain four unique values, your code will be in an infinite loop. Remember also that RANDBETWEEN can return the same number more than once. Can you show a sample of the data for the sheet where it gets stuck? You could add some Debug.Print statements at key points to trace what is going on.


    I rewrote your code to eliminate that GoTo, an undesirable practice:


    The code in your first post does not work in the file you attached so I am at a dead end.


    When I tried the sort approach you just showed, the sort order did not match the example you gave in the file. Also, the table in the Calculation sheet is Table2, not Table1 as shown in your latest code.

    Here in W10 =CONCATENATE(B10,O10) and in B10 I have ID and O10 =IF(B10="","",MONTH(H10) & YEAR(H10))

    And none of that is anywhere in the file you attached. So I really don't understand what you're doing.


    Glad you worked it out.