Created
October 23, 2016 21:01
-
-
Save martinctc/dff9bb50567421d1b4d53a67753731d0 to your computer and use it in GitHub Desktop.
Use this snippet for creating dynamic arrays from rows of data in Excel.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub DArrayCreator() | |
Dim wb As Workbook | |
Dim ws As Worksheet | |
Dim i, j, k As Integer | |
'Use this snippet for creating dynamic arrays from rows of data in Excel. | |
'Current snippet only allows for two columns of data. | |
'Enter source workbook location here | |
'Set wb = Workbooks.Open("C:\Users\Martin\Desktop\ArrayReplacer.xlsx") | |
Set wb = ActiveWorkbook | |
Set ws = wb.Sheets("Sheet1") | |
'Counts number of cells in column A | |
k = ws.Application.CountA(Range("A:A")) | |
Dim ListA(), ListB() As Variant | |
ReDim ListA(1 To k), ListB(1 To k) | |
For i = 1 To k | |
ListA(i) = ws.Range("A1").Offset(i) | |
Next i | |
For i = 1 To k | |
ListB(i) = ws.Range("B1").Offset(i) | |
Next i | |
'Indicates what values are included in your array. | |
Debug.Print "ListA has " & UBound(ListA) & " values." | |
Debug.Print "ListB has " & UBound(ListB) & " values." | |
'For i = LBound(ListA) To UBound(ListA) | |
' msg = msg & ListA(i) & vbNewLine | |
'Next i | |
'Debug.Print "The values of my dynamic array (ListA) are: " & vbNewLine & msg | |
End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment