camper12
asked on
Matrix/array in vba
Hi,
pfa a picture. I want to read data from the rows in the excel into a matrix/array in vba. Then i want to loop through the matrix and execute the macro for each row/record. For example, in the picture I have uploaded, I want to store 2 rows in a matrix and loop through each row to run a macro. Please provide code for this.
UT NG 3 7
FI BA 7 10
Thanks
pfa a picture. I want to read data from the rows in the excel into a matrix/array in vba. Then i want to loop through the matrix and execute the macro for each row/record. For example, in the picture I have uploaded, I want to store 2 rows in a matrix and loop through each row to run a macro. Please provide code for this.
UT NG 3 7
FI BA 7 10
Thanks
Quick question post storage..can you help me understand what you are looking for?? Also if you can post a sample file with results before and after it will help to design a code for you accordingly..
ASKER
I did post the excel snapshot. I am trying to get the rows in a matrix data form into vba so that I can loop through it. Note the values have different data types.
Camper12,
From the snapshot i get how does your data look like but i'm not sure post which what result you are looking for?? Or what you are trying to do here??
Saurabh...
From the snapshot i get how does your data look like but i'm not sure post which what result you are looking for?? Or what you are trying to do here??
Saurabh...
ASKER
This is my code:
l2 = ActiveSheet.Range("D" & Rows.Count).End(xlUp).Row
l3 = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
l4 = ActiveSheet.Range("F" & Rows.Count).End(xlUp).Row
lLB = ActiveSheet.Range("G" & Rows.Count).End(xlUp).Row
lUB = ActiveSheet.Range("H" & Rows.Count).End(xlUp).Row
lastRow = Max(lastRowClass2, lastRowClass3, lastRowClass4, lastRowLB, lastRowUB, lastRow)
Dim MyRange As String
Dim InputRecords As Variant
MyRange = "B1:D" & "lastRow"
InputRecords = Range(MyRange)
In this code I am trying to find the lastRow based on Max(lastRowClass2, lastRowClass3, lastRowClass4, lastRowLB, lastRowUB, lastRow). Max does not work in vba. Is there some solution/alternative to it?
Also, once I get last row, I want to put this in a variant and then loop the rows.
Thanks
l2 = ActiveSheet.Range("D" & Rows.Count).End(xlUp).Row
l3 = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
l4 = ActiveSheet.Range("F" & Rows.Count).End(xlUp).Row
lLB = ActiveSheet.Range("G" & Rows.Count).End(xlUp).Row
lUB = ActiveSheet.Range("H" & Rows.Count).End(xlUp).Row
lastRow = Max(lastRowClass2, lastRowClass3, lastRowClass4, lastRowLB, lastRowUB, lastRow)
Dim MyRange As String
Dim InputRecords As Variant
MyRange = "B1:D" & "lastRow"
InputRecords = Range(MyRange)
In this code I am trying to find the lastRow based on Max(lastRowClass2, lastRowClass3, lastRowClass4, lastRowLB, lastRowUB, lastRow). Max does not work in vba. Is there some solution/alternative to it?
Also, once I get last row, I want to put this in a variant and then loop the rows.
Thanks
You can just simply do this..
This will find automatically last filled row of your data..
Saurabh...
lastrow = Cells.Find(what:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
This will find automatically last filled row of your data..
Saurabh...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.