filmov
tv
VBA Loop on array's columns

Показать описание
Loop on all columns of an array.
Code:
Sub loop_on_columns_Array()
Dim ws_sheet As Worksheet
Dim lastrow As Long
Dim lastcolumn As Long
Dim array_data() As Variant
'identify worksheet
Set ws_sheet = Worksheets(2)
'find table's limits
lastrow = ws_sheet.Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = ws_sheet.Cells(1, Columns.Count).End(xlToLeft).Column
'save table in array
array_data = ws_sheet.Range(ws_sheet.Cells(1, 1), ws_sheet.Cells(lastrow, lastcolumn))
'loop on columns
For j = LBound(array_data, 2) To UBound(array_data, 2)
'your code here
'example: read columns header
MsgBox ("Header of the column " & j & ": " & array_data(1, j))
Next
End Sub
-------------------------------
NEED HELP?
-------------------------------
Leave a comment with your questions, issues or projetcs and I will try to answer with a video.
-------------------------------
THANK YOU
-------------------------------
For watching my videos,
Your shares
And your comments!
Code:
Sub loop_on_columns_Array()
Dim ws_sheet As Worksheet
Dim lastrow As Long
Dim lastcolumn As Long
Dim array_data() As Variant
'identify worksheet
Set ws_sheet = Worksheets(2)
'find table's limits
lastrow = ws_sheet.Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = ws_sheet.Cells(1, Columns.Count).End(xlToLeft).Column
'save table in array
array_data = ws_sheet.Range(ws_sheet.Cells(1, 1), ws_sheet.Cells(lastrow, lastcolumn))
'loop on columns
For j = LBound(array_data, 2) To UBound(array_data, 2)
'your code here
'example: read columns header
MsgBox ("Header of the column " & j & ": " & array_data(1, j))
Next
End Sub
-------------------------------
NEED HELP?
-------------------------------
Leave a comment with your questions, issues or projetcs and I will try to answer with a video.
-------------------------------
THANK YOU
-------------------------------
For watching my videos,
Your shares
And your comments!
VBA Loop on array's columns
How to Use Arrays Instead of Ranges in Excel VBA
VBA For Loop - A Complete Guide
VBA Loop on array's rows
AdvFinMod Topic 5 Section 7 VBA Nested Loops and Multidimensional Arrays
Excel VBA Arrays For Beginners
VBA: For-Next Loop Examples
VBA Arrays Explained in 3 Minutes
Excel Formatting Made Easy: VBA Arrays for Dynamic Column Fixes
How to Master VBA loops FAST (with real coding examples)
Use a For Loop and If Statement to loop through an Array and add data to another Sheet in VBA Code
Pro Microsoft Excel VBA Course | For Each Loop VBA Example | Get Column Value | Part - 9.5 |
VBA Paste multiple columns array on sheet
Excel VBA Read and Write Data to Arrays
Arrays in VBA
Nested Loops - EXCEL/VBA
013. Excel VBA Array Example (incl. resizing / Dynamic arrays) - Manipulate arrays like a pro
Excel VB Instr, For Loop, Arrays and Transpose
Learn Excel - 94 - VBA Arrays and Loops - Split the text in Style
Re dimension array | Redim array in vba | preserve array in vba
Create #Array and Fill Data #excel #shorts #vba #exceltutorial
Local Arrays in Excel VBA
VBA Subs and Functions with Arrays
How To Loop Across Columns In VBA
Комментарии