I should preface this question by stating that I have 0 experience using any of the advanced features of Excel, and now that I need to use them, I have no idea what I am doing.
I need to generate an excel table with the following columns: ID, firstname, lastname, password, and phone in each column. I need N entries in each column, where ID, firstname, and lastname are just random characters, up to X characters, password is random upper case, lower case, and alphanumeric characters, up to Y characters, and phone is a random 10 digit int. I can generate the random strings easy enough, its checking to make sure the content is unique to anything else already in the table and adding it that I have no clue about. I am on a Mac, so this could also be done in bash, creating a csv file, another area I know very little about, but I figured since it is Excel specific, and I am going to need similar skills going forward, I should start learning VBA.
If I understand correctly, you are worried the ID, say, you generate on row N is the same as the one you generated for one of the rows in the range 2 to N-1.
I do not know of a VBA function that will report if a value matches or fails to match any value in a range. You are using the MAC while I use the PC but I doubt that makes a difference.
You seek a five column table. You must have a number of rows in mind, say Max. You want row 1 to hold a heading line. You say you know how to generate the random values for each column.
I know there are subtle differences between MAC and PC VBA but I assume the following is common.
I would generate the table in an array which will be much faster than accessing worksheet cells.
This above will convert WkshtValue to an array of the required size and copy to it all the values within the range of interest. Because WkshtValue is Variant, the entries within the array will be strings, integers, dates or whatever they were within the worksheet.
This array will be one based regardless of the position of the range within the worksheet so it hurts my brain less if the range is one based.
The first dimension of WkshtValue will be for rows and the second will be for columns. This is not the normal convention but it means
WkshtValue(Row, Col)
matches.Cells(Row, Col).Value
.It is marginally more difficult to do the opposite but you can define an array, fill it with values and then write is to the worksheet:
I would code a function
RanVal(ColCrnt) As String
that returned a random value appropriate for columnColCrnt
.I would then have something like:
The above code was typed straight into the answer and not tested. I cannot see any syntax errors but no promises. Come back if I have made a mistake you cannot correct.
Hope this gives you some ideas.