Capturing and calling items in a dynamic VBA array

moltke

New Member
Joined
Apr 18, 2013
Messages
6
I have an exported file, basically an Excel text spreadsheet with column headers and around 2000 lines. It can change, so I don't have a fixed array size. I have stumbled through things where I believe I can build the array, but get lost on essentially how to call out and display specific parts of the array based on criteria and entries. In short, what would be the easiest method to code in VBA the following. Create array from <exported Excel file>, Display or Build new array using statements and queries upon the array previous built. Example. Populate a new sheet, projecting entries to cells as I need to call them out of the overall array. So, say I want all those that have <condition> in column f, and/or <condition 2> in column ab, with total number of lines with <condition 3> in column c, to be populated in new sheet to certain cells. I need to repeat various sets of conditions like this through the entire array and be able to call cells within those findings that meet those conditions.

I'm capable of doing these on 1 to 1 questions, but I don't have the skills I guess to have my array's work with my do while loops to populate the new area. Any tips would be appreciated. Sorry if that is confusing. Thanks.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Firstly I don't know what you mean by "calling"
Your requirements are a bit vague but here is some code that checks for a match between "Rabbit" in column F and the number 1 in column AB on the active sheet and copies rows that match to sheet 3.
You haven't said whether your conditions are always the same or need to be user defined, how different sets of conditions you have and how you want to handle the different sets,
VBA Code:
Sub test()
Dim outarr()
cond1 = "Rabbit"
cond2 = 1
lastrow = Cells(Rows.Count, "F").End(xlUp).Row ' find last row with dat in columnn F
inarr = Range(Cells(1, 1), Cells(lastrow, 28)) ' pick up all the data from column A to column AB ( 28)
ReDim outarr(1 To lastrow, 1 To 28) ' define output same size as input incase we need everry row
indi = 1
For i = 1 To lastrow
 If inarr(i, 6) = cond1 And inarr(i, 28) = cond2 Then
  ' copy row
   For j = 1 To 28
    outarr(indi, j) = inarr(i, j)
   Next j
   indi = indi + 1
  End If
 Next i
 With Worksheets("Sheet3")
  If indi > 1 Then
   .Range(.Cells(1, 1), .Cells(indi - 1, 28)) = outarr
   End If
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top