i'm prototyping a solution for a tidious task using vba because my company's security only allows this method, can't use python nor anything else.
i have a table of 5K+ rows and about 15 columns, and i want to process it removing specific columns based on a search criteria.
so here's my code so far
Sub RstCr()
Dim Sh As Worksheet
Dim Ar() As Variant
Dim Arr As Variant
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim p As Integer
Set Sh = Sheets("Sheet1")
Sh.Cells(1, 1).CurrentRegion.Select
Ar = Sh.Range("A1").CurrentRegion.Value
MsgBox UBound(Ar, 1)
Arr = Array("COFOR", "Tri", "Fournisseur", ".Tiers.All", "GrM")
For i = 0 To UBound(Arr)
For j = 1 To UBound(Ar, 2)
If Ar(1, j) = Arr(i) Then
For k = j To UBound(Ar, 2) - 1
For p = 1 To UBound(Ar, 1)
Ar(p, k) = Ar(p, k + 1)
Next p
Next k
End If
Next j
ReDim Preserve Ar(UBound(Ar, 1), UBound(Ar, 2) - 1)
Next i
Worksheets("Sheet2").Range("A1").Resize(UBound(Ar, 1) , UBound(Ar, 2)).Value = Ar
End Sub
My question is: how would an experienced vba developper rate this code, how efficient is it. Also, is there a better way to prcessing arrays other than the tetris approach (for example, to delete a column nothing works other than the method above).
the program has more tasks: - Inserting columns between specific columns - filling those columns with values available in another table containing corresponding values of cells in the first array - removing duplicates based on two columns - sorting array rows based on one column.
would continuing with the current approach still make sense or there is a better and easier way to do it.
Thank you.