I have been helping a team with automating their sheet and got like 98% of the way there and realized that I don't think I can use the method I utilized to get the 98%. Basically in the matrix file users are filling out info in sheet 1 columns A & B. I wanted to have the macro generate the entirety of sheet 2 and the last column on sheet 3. You can see from the macro that everything works EXCEPT row 2 on sheet 2. When I create the table it starts with headers, and then when those are deselected it moves the table. In the process of fixing this by just moving the table I realized i used arbitrary numbers when defining the columns of the table, I figured id use the rowcount of sheet 3 to define the columns of the table and realized that sheet 3 has over 100 rows and sheet 2 does not have the same number of columns. This indicated to me that the team was creating new columns in sheet 2 as they found something that would match sheet 3. The issue is that sheet 3 will expand.
I figured I would add the title of the columns of sheet 2 from scratch by creating a title for every unique ID that appears in column B of sheet 1 (the one the users fill out)
I have gotten this code so far
Sub storeunique()
Dim data(), dict As Object, r As Long, n As Integer, I As Integer
Dim columncounta As Integer, rowcounta As Integer
Dim t() As String
Dim a
With Sheets("Step 1")
a = .[A1].CurrentRegion
columncounta = UBound(a, 2)
rowcounta = UBound(a, 1)
End With
Set dict = CreateObject("Scripting.Dictionary")
For I = 2 To rowcounta
t = Split(a(I, 2), ",")
For r = 0 To UBound(t, 1)
dict(Trim(t(r))) = Empty
Next r
Next I
data = WorksheetFunction.Transpose(dict.Keys())
End Sub
the variable data is a variant array with each unique ID and the count of those unique instances, the issue being that it stored them in the order they appeared and if you look at the non xslm sheet, these need to be in order. To make matters worse, some ID's are numeric and some are text "i, ii, iii, iv, N/A" etc. I do not think it is going to be an issue if the text is placed before or after the numbers but I am at my limit of VBA knowledge trying to figure out a good way to paste the values of data into the columns of sheet 2 in order. Does anyone have any tips?
EDIT: 3/7/25 3:42 pm MST
I ended up adding this to the end of my code and it worked. Posting here in case anyone else wants to use it or has a better idea
For I = 1 To UBound(data, 1)
If IsNumeric(data(I, 1)) Then
data(I, 1) = CInt(data(I, 1))
Else
End If
Next I
outputarray = WorksheetFunction.Sort(data, 1)
Bookmarks