Code:
'
Sub Clms()
Dim Ws As Worksheet: Set Ws = ThisWorkbook.Worksheets("IndexWithArraysWTF") '--Change to Suit Your Sht Preferrence
Dim Clms() As Variant: Let Clms() = Evaluate("=column(A:H)") ' Returns 1, 2, 3, 4, 5, 6, 7, 8
Dim vTemp As Variant: Let vTemp = Evaluate("=mod(column(A:H),4)") 'Retuns Long Number 1
Let Clms() = Evaluate("=If(column(A:H),mod(column(A:H),4))") 'Returns 1, 2, 3, 0, 1, 2, 3, 0
Let Clms() = Evaluate("=If(column(A:G),mod(column(A:H),4))") 'Returns 1, 2, 3, 0, 1, 2, 3, error
Let Clms() = Evaluate("=If(column(),mod(column(A:H),4))") 'Returns 1, 2, 3, 0, 1, 2, 3, 0
Let Clms() = Evaluate("=If(row(),mod(column(A:H)-1,4))") 'Returns 0, 1, 2, 3, 0, 1, 2, 3
Let Clms() = Evaluate("=Index((mod(column(A:H)-1,4)+1),)") 'Returns 1, 2, 3, 4, 1, 2, 3, 4
End Sub
Sub Rws()
Dim Ws As Worksheet: Set Ws = ThisWorkbook.Worksheets("IndexWithArraysWTF") '--Change to Suit Your Sht Preferrence
Dim Rws() As Variant: Let Rws() = Evaluate("=column(E:L)") ' Returns 5, 6, 7, 8, 9, 10, 11, 12
Let Rws() = Evaluate("=Index((int(column(E:L)/4)),)") 'Returns 1, 1, 1, 2, 2 ,2, 2, 3
Let Rws() = Evaluate("=Index((int((column(E:L)-1)/4)),)") 'returns 1, 1, 1, 1, 2, 2, 2, 2
Let Rws() = Evaluate("=Index(((int((column(E:L)-1)/4))+1),)") 'returns 2, 2, 2, 2, 3, 3, 3, 3
End Sub
'
Sub AppIndexRT23C1234()
Dim Ws As Worksheet: Set Ws = ThisWorkbook.Worksheets("IndexWithArraysWTF")
Dim Rws() As Variant: Let Rws() = Evaluate("=row(2:3)") 'Returns 2 D 1 "column" Array , values 2 / 3
Dim Clms() As Variant: Let Clms() = Evaluate("=column(A:D)") ' Returns 1, 2, 3, 4
Dim arrOut() As Variant
Let arrOut() = Application.Index(Ws.Cells, Rws(), Clms())
End Sub
'
Sub AppIndexRT23CT1234()
Dim Ws As Worksheet: Set Ws = ThisWorkbook.Worksheets("IndexWithArraysWTF")
Dim Rws() As Variant: Let Rws() = Evaluate("=row(2:3)") 'Returns 2 D 1 "column" Array , values 2 / 3
Dim Clms() As Variant: Let Clms() = Evaluate("=row(1:4)") 'Returns 2 D 1 "column" Array , values 1 / 2 / 3 / 4
Dim arrOut() As Variant
Let arrOut() = Application.Index(Ws.Cells, Rws(), Clms())
End Sub
'
Sub AppIndexR23CT1234()
Dim Ws As Worksheet: Set Ws = ThisWorkbook.Worksheets("IndexWithArraysWTF")
Dim Rws() As Variant: Let Rws() = Evaluate("column(B:C)") 'Returns 1 D Array 2, 3
Dim Clms() As Variant: Let Clms() = Evaluate("=row(1:4)") 'Returns 2 D 1 "column" Array , values 1 / 2 / 3 / 4
Dim arrOut() As Variant
Let arrOut() = Application.Index(Ws.Cells, Rws(), Clms())
End Sub
Code:
Sub burakGenerateSequentialColumnIndiciesFromLetters() 'Dec 9 usefulgyaan.wordpress.com/2013/06/12/vba-trick-of-the-week-slicing-an-array-without-loop-application-index/
'Variables for...
Dim LB As Long, UB As Long '...User Given start and Stop Column as a Number
Let LB = 2: Let UB = 25
Dim strLtrLB As String, strLtrUB As String '...Column Letter corresponding to Column Number
'There are many ways to get a Column Letter from a Column Number - excelforum.com/tips-and-tutorials/1108643-vba-column-letter-from-column-number-explained.html
Let strLtrLB = Split(Cells(1, LB).Address, "$")(1) 'An Address Method
Let strLtrUB = Replace(Replace(Cells(1, UB).Address, "1", ""), "$", "") 'A Replace Method
'Obtain Column Indicies using Spreadsheet Function Column via VBA Evaluate Method
Dim Clms() As Variant
Let Clms() = Evaluate("column(" & strLtrLB & ":" & strLtrUB & ")") 'Returns 1 D "pseudo" Horizontal Array of sequential numbers from column number of LB to UB
'Or
Clms() = Evaluate("column(" & Split(Cells(1, LB).Address, "$")(1) & ":" & Replace(Replace(Cells(1, UB).Address, "1", ""), "$", "") & ")")
End Sub
Bookmarks