Results 1 to 2 of 2

Need to paste a variant array in numeric order

Threaded View

MDLovitt Need to paste a variant array... 03-07-2025, 05:17 PM
6StringJazzer Re: Need to paste a variant... 03-08-2025, 11:04 AM
  1. #1
    Registered User
    Join Date
    07-18-2024
    Location
    United States
    MS-Off Ver
    MS 365
    Posts
    33

    Need to paste a variant array in numeric order

    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)
    Attached Files Attached Files
    Last edited by MDLovitt; 03-07-2025 at 06:55 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Problem with array types: variant vs. string array when appending data to a .csv
    By Rabk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-15-2022, 04:31 PM
  2. [SOLVED] A variable defined as variant or variant array
    By billj in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-14-2016, 05:35 PM
  3. [SOLVED] Type Mismatch, variant variable although numeric won't allow numeric manipulation
    By Rokn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2016, 04:02 PM
  4. Replies: 1
    Last Post: 07-25-2016, 03:09 PM
  5. [SOLVED] Copy and paste from random order to alpha-numeric order
    By OthelloDog in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-03-2016, 11:11 PM
  6. Does setting a variant acting as an array equal to "" accomplish same as "Erase" variant?
    By dmasters4919 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2014, 05:59 PM
  7. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2005, 12:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1