Fill Array To Execute Loop?

Apr 25, 2014

how to fill array with cells form selections and loop my macro for each cell of that array.

Code:
'this is macro I need to execute for each cell in my selection. Here I threat each cell from selection as solo selection.

Sub SELECTION_CELL_COUNT_SINGLE()
Dim z As Integer, q As Integer, X As Boolean, I As Integer, txt As String
Dim tmp As String, J As Integer, K As Integer
Dim sStrip As String

[Code]....

View 1 Replies


ADVERTISEMENT

Recursively & Conditionally Move/Loop Through Folder Hierarchy To Fill Array

May 7, 2008

i am use dir to put into an array all the folders in a folder then enter the first folder and repeat. the problem i am having is when it encounters a file it also puts it into the array and then errors once it trys to enter that "folder" (which is a file)

right now the code doesnt do anything but the plan is then to call another subroutine that lists all the files im looking for in a folder (that sub does work)

what am i doing wrong? all the things i can find on google show it the way i am doing it.

Sub GetDirList(topfolder As String)
Dim FolderArray() As Variant
Dim FolderCount As Integer
Dim FolderName As String

FolderCount = 0
FolderName = Dir(topfolder, vbDirectory)
' Loop until no more folders are found
Do While FolderName <> ""
If Not FolderName = "." Then
If Not FolderName = ".." Then
FolderCount = FolderCount + 1
Redim Preserve FolderArray(1 To FolderCount)
FolderArray(FolderCount) = FolderName
End If
End If

View 3 Replies View Related

Loop Through All Sheets And Execute

Nov 19, 2011

I have this very simple code below that I use to delete a row if its marked as 'false' in column M. This works quite well, but I want to expand it. I use this in a workbook that can have name different sheet names in a month, and I want it to automatically go through all the sheets and do this...except for 2 sheets named addressess and sheet1. Is there something I can add to this macro that will loop through all the other sheet names (regardless of name) and execute this?

Sub DelRow()
With ActiveSheet
.AutoFilterMode = False
With Range("m1", Range("m" & Rows.Count).End(xlUp))
.AutoFilter 1, "false"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub

View 2 Replies View Related

Loop To Increment Row Number And Execute Command Where Set The Formula

Oct 11, 2011

Make a loop where I can increment the row number and execute the command where I set the formula?

View 1 Replies View Related

Loop Through Of Sheets And Execute Calculations Based On Dynamic Sheet References

Jun 30, 2014

Is it possible to loop through a list of sheets and execute some calculations that have sheet references from a different list of worksheets? For example, you have a list (list 1) of your worksheets, which will be the destinations of the calculations, and you have a second list (list 2) of worksheets that the calculations are based on. So, lets say there are sheet1 and sheet2 in list 1, and sheetA and sheetB in list 2. The calculations based on sheetA would appear in sheet1, and calculations based on sheetB would appear in sheet2. I thought the code would look something like this:

Code:
Sub LoopthroughWorksheets()
Dim sheet_name As Range
Dim sheet_name2 As Range
Set sheet_name2 = Sheets("WS").Range("F:F")

[Code] ......

I'm getting a "Run-time error '1004: Application-defined or object defined error" at this line:

Code:
.Range("K1") = .Range("sheet_name2.Value!A14").Value

View 2 Replies View Related

Change From Execute On Selections To Execute On All

Feb 28, 2014

I have the following code:

[Code] .......

What do I need to change in order to make it execute the Call statement on EVERY item in the ListBox2, not the Selections.

View 3 Replies View Related

Macro To Do A Loop Instead Of Fill Down

Apr 10, 2012

I have a row of data. The first few columns are given data, and then the next few columns are equations that use the first few columns of data.

The next row down adds the result of a few of the equations in the row above it to the given data, and the equations are calculated again.

It looks a bit like this:

1231437-111213-9

in the first row, 1 and 2 are just given. 3 is just 1+2 (a1+b1), and in the last column, 1 is just 2-1 (b1-a1). In the second row, A2 is A1+C1, and B2 is just B1+D1, C2 and D2 are the same calcs as C1 and D2.

This row is then filled down.

What I would like to do, is just calculate what the first two columns of data are by just entering the number of cycles id like to make, instead of filling down the row.

For example, I would like to just enter N=3 in a cell, and it returns 11 and 2. Or N = 1000 and it would give me whatever the first two values are if i had filled the row down 1000 rows.

View 2 Replies View Related

Array () Vs. Loop

Jun 13, 2008

when is it appropriate to us arr(1 to 10) Vs. For i = 1 to 10. I know this may sound like a silly question and expose my ignorance - but I suppose there is no other way to learn :|

View 9 Replies View Related

Fill Listbox With Array Of Folders

Jan 26, 2010

(Modifying some code by Leith Ross) I am stumbling why I get an error trying to fill the listbox with folder names. (See code in red for error location) ....

View 9 Replies View Related

Fill ComboBox With 2 Dimensional Array

Oct 9, 2004

I can set up a 2 dimensional array by using

array = Workbooks("Workbook.xls").Worksheets("Data"). Range("D_all")

as range D-all contains 2 columns and 20 rows

I can send that list to a combo box by using

Me.ComboBox1.List() = array

If I have ColumnCount set to 2 then both columns will be listed

If I have ColumnCount set to 1 then the 1st part of the array will be listed

But how do I list just the 2nd part of the array

View 8 Replies View Related

Fill Array By Looping Worksheets

Aug 23, 2007

I am trying to write code that will loop through one sheet, fill an array and then use that array to populate cells in another sheet. I have a sheet with group names in column A, then in column B through Column IV there are the members of that group. There may be no members in a group or every cell through Column IV could contain data. I need to loop through each row, one at a time, see if a cell contains data, if it does, put it in the array, if it's empty then the array is done for that row. I then need it to go to another sheet and dump that data, however, now it needs to drop it in five consecutive cells in a row, then drop to the next row for the next five cells, etc.

Once this is done it then goes back to the first sheet, drops to the next row nad starts over.

I know how to loop through the rows, I just am not sure how to fill an array using variables for rows and columns. i.e., I can't say fill array with b1 to b30 instead I have to say fill array with intRow,intFirstColumn through intRow, intLastcolumn.

View 6 Replies View Related

Fill Array Variable From Range

Jun 14, 2008

I've created a userform that uses parallel arrays to display strings that another macro pulls from a worksheet and the 2nd array holds strings of what the user types in. I've uploaded a workbook with the userform in it.

Part 1:
I want to pass the 1st array (pSource) in during the initialization of the array and I want to send back the 2nd array (pUser) from the submit button, but I have no idea how to work it. I've tried a couple things from older posts in the forums, but had no luck with them.

Part 2:
The arrays will be the same size, but the size isn't a constant. Is there any way to change the size of an array? I've been using 0 to 3 for testing the rest of the userform, but for the final product, I'll be passing an array in of a variable size.

Private pSource(3) As String 'Modify to work with variable size
Private pUser(3) As String 'Modify to work with variable size

View 3 Replies View Related

Array Name Loop Through Variables

Jun 17, 2013

I am trying to loop through different SlicerCaches but it doesn't seem to work.

Here is the code, I am trying,

VB:
Test_Name = Array("[Test - Test Allocation]", "[Test 2]")
For i = LBound(Test_Name) To UBound(Test_Name)

ActiveWorkbook.SlicerCaches("Slicer_Exec_Function_Summary1").VisibleSlicerItemsList = Array("[Mercury].[Exec Function Summary].&" & Test_Name & "")

The code returns a mismatch 13 error.

When I try it without an array, it works fine.

VB:
Test_Name = "[Test - Test Allocation]"
ActiveWorkbook.SlicerCaches("Slicer_Exec_Function_Summary1").VisibleSlicerItemsList = Array("[Mercury].[Exec Function Summary].&" & Test_Name & "")

View 3 Replies View Related

Sum Portion Of Array Without Loop

Jun 24, 2009

I faced a problem to attach this small WB as an XLS

I'm looking for some way to some the red cells without looping.

In this example the array was filled with A1:A10 values.
In the real situation the array gets its values from other source than a Worksheet Range.

As you can see I manged to transport the Array Values to F1:F10 and from here I could calculate the sum of F3:F8 but I do not want to use any helper columns.

View 12 Replies View Related

Defining An Array To Use In For Next Loop

Feb 13, 2007

I have created some code of which this is an extract

Dim i As Variant

i = Array(37, 38, 41, 42)

For Each i In i

'Some Code
Next i

the routine works fine when the i variable is hard coded, but once the above is included it fails (Error 10 This array is fixed or temporarily locked).

View 3 Replies View Related

Fill Array With Userform ComboBox Names

Apr 13, 2009

Is it possible to count the number of comboboxes on a userform? Or better yet can I fill an Array with all the combobox names on a userform? I can count the controls on a userform but I'm trying to count just the comboboxes? Instead of all the labels and textboxes and frames.

I would like to loop through them for validation instead of doing it by each one by itself!

View 9 Replies View Related

Fill Range From Multi-dimensional Array

Jul 20, 2007

I searched and found a few posts about transposing arrays into a range of cells, but none of them seemed to solve my problem. So, my problem is, I have a .Net assembly which provides various functions to allow Excel to access our Oracle DB stored procedures/tables, etc. This assembly is exposed via COM Interop. I call the GetSPINTypes() method, which returns me a list of type pairs (ID, Name), in a CSV string format.

I split the CSV into rows, and then put each row into a 2-dimensional array.
I then need to dump that array into one of my sheets in Excel, so I try to do the usual Range.Value = Array, but this sometimes tells me there is a type mismatch, and most times just doesn't fill the range. I've checked my arrays in the watch window, and they have definitely been filled in correctly, the values just don't appear when they are put into the sheet. See the code I'm using below:......

View 4 Replies View Related

Fill MultiColumn Listbox With Part Of Array

Sep 21, 2007

I have a multicolumn listbox, and a multidimensional array.

I want to put just SOME values of the array into the listbox, but I ger errors using both .list or .column to access single items, and even using .additem .

I have:
dim variable(2000,2) as string
variable(1,0)="aaa": variable(1,1)="bbb": variable(1,2)="ccc"
variable(2,0)="www": variable(2,1)="awasd": variable(1,2)="asdfa"
....
variable(2000,0)="www": variable(2000,1)="awasd": variable(2000,2)="asdfa"

I don't want to store all 2000 elements, just some ones: how can I do it?

View 9 Replies View Related

Fill & Rearrange Multi-dimensional Array From Another

Feb 26, 2008

I've got the folowing array's

date1>company1>price
>Company2>price
>company3>price
>enz

Date2>company1>price
>company2>price
>enz

enz.

But these are not the array's that i need for a correlation that i want to make.
Is it possible to transform the array's above to an array such as:

Company>date1>price
>date2>price
>date3>price
>enz

View 5 Replies View Related

Using Array To Quickly Loop Through Data

Jul 5, 2014

I've built a simple inventory tracking system, and decided a reporting feature would be nice. There are four categories that are entered when inventory is removed...Date, Employee Name, Item Description, Location, and quantity.

Four my reporting purposes I'm only concerned with Date, Employee name and Item Description.

I've been able to write code that does what I want using a multiple Cases and a For loop once the case is identified. However, the more data there is the longer this takes...so I decided to stretch myself and try my hand at arrays (first time really working with arrays), but I'm having trouble figuring out exactly what I need to do.

Here is what I think the steps need to be.

1. Store my data (the categories above) which are located in the Check Out sheet
2. Go through the arrayed data to find exact matches based on my search criteria (here is where the Cases come in)
3. Pull out only that data and write the information to a "Report" Sheet
4. Export that sheet to PDF (this part I already have)

Below is a copy of what my current "working" code looks like (I should mention that the search selections are made from a userform this is what the Cases are deciphering between which ones are blank etc...), also most of my variables are instantiated as Public variables within a Public_Variables module also below.

[Code] ....

And the Public Variables...

[Code] ....

View 4 Replies View Related

If / Then And For Loop - Isolating File In Array

Feb 28, 2013

I have a For loop, its an array with 5 file names in it. The loop checks for the files in the path, and if the file is there it places the file in the corresponding sheet in the workbook. If it is not, I get the option to browse for the file. Originally all 5 files were required, however now the requirements changed and only 4 are required the last file "byband.csv" is not required. So they want the option a message box telling the user the file is not required they can browse or keep going.

I worked out the second part but only by taking "byband.csv" out of the loop and writing a separate procedure for it, I wondered if in my original procedure I could isolate "byband" and if not found go to another part of the procedure. Basically, I needed to do the following:

If the file in the array byBand.csv is not found, Then:

vmbProceed = MsgBox(strFifthImportFile & strMessage, vbYesNo + vbQuestion, strTitle)
If vmbProceed = vbNo Then
Exit Sub
Else

go to Line 1 in the procedure below.

Code:

Sub import_Employee_Data()

'This is Step 1 when the frmDataImportSplash is activated.
'This procedure imports the byEmployee.csv sheet. The procedure checks if the file is
'in the same directory as the template. If the file is not there, a browser window appears to allow the user
'to browse for the missing file. A series of message boxes guide the user through the process and
'verifies that the user picked the right file. The user can cancel the import at any time.

Dim strPath As String
Dim strFirstImportFile As Variant

[Code] .........

View 8 Replies View Related

Use Array To Store All The Results Of The For Loop

Jun 19, 2008

I would like to use array v to store all the results of the for loop u...How can Ido it?

Dim myRange As Range
Dim AnsRange1 As Integer
Dim AnsRange As Range
Set myRange = Application.InputBox(Prompt:="Select row to insert 10 rows below", Type:=8)
AnsRange1 = myRange.Row
Dim u As Integer
Dim v As Integer
Dim var() As Single
v = 0
For u = 23 To 24022 Step 9
var(v) = u
Next u
If Not (AnsRange1 = v) Then
MsgBox AnsRange1
Else
Range(AnsRange1 & ":" & AnsRange1 + 9).Insert Shift:=xlDown
End If
End If

View 9 Replies View Related

Loop Through Array And Perform Formula

May 10, 2006

trying to loop through an array, with each loop calculating a formula (VLOOKUP) for one cell based on the values of a cell in another sheet.

Not sure but I think it has something to do with looking up a text value while the loop returns a value.

Private Sub ExpandFormula()
'calculates Counttarget formula in COUNTTARGETS sheet across required range
Dim CellsDown As Long, CellsAcross As Integer
Dim i As Long, j As Integer
Dim TempArray() As String
Dim TheRange As Range
Dim CurrentValue As String

'get the dimensions
CellsDown = Worksheets("SEPARATE").Range("D9").Value
CellsAcross = Worksheets("SEPARATE").Range("E9").Value

'redimension temporary array
Redim TempArray(1 To CellsDown, 1 To CellsAcross) .....................

View 9 Replies View Related

Advance Variant Array Without Loop

Jul 13, 2006

Is it possible to use an array without looping through it? I have code that has two loops: One that is just for the array and the other that loops through the data. It would be nice if I could get it down to one loop, but I'm not sure if it's possible. For example, if you have
Dim varArea As Variant

varArea = Array(1,2,4,6,8,12)

For x = LBound(varArea) To UBound(VarArea)
Do While Not C Is Nothing
Code here
Is there a way to advance to the next item in the array without using the loop.

View 10 Replies View Related

Fill Array From Range Selecting All Rows And Some Columns

Jul 21, 2014

I want to fill an array from values in range A1:H10. I want to fill the array with all rows in range and only columns B,C and E. I have the code below so far using index function.

Is there a more direct way to select all rows from desired range to avoid the need to create an array of rows from 1 to LastRow and then use Application.Transpose(RowsArr) (in red) inside Index()?

View 3 Replies View Related

Array With Button Names, Call Them One By One In A For Loop

May 12, 2009

I am having a problem calling buttons. I have an array with button names and another array with their caption texts and I would like to call them one by one in a for loop:

For i = 1 To UBound(button_array)
Sheets("Statistic").Shades(button_array(i)).Caption = button_text(i)
Next i

But the only way I seem to be able to call them is by their set names, like:

Sheets("Statistic").statistic.Caption = button_text_ENG(i)

View 2 Replies View Related

Error Filling Array With Only Few Values Within Loop

Feb 26, 2014

I am trying to fill an array with only a few values within a loop (when XspacingA is 0.5, add the value of the Line to the array) and keep getting the error "Subscript out of range".

View 3 Replies View Related

Macro To Loop Through Sheets And Print Them Out Using An Array

Aug 4, 2009

I have created a macro that loops through and creates an array of the visible sheets. Now I would like for it to print each of those sheets out. I think my main mistake is in my declaration of the array type, since I have not worked with arrays much before.

how to make the following code operable. Currently when I run it I'm getting a "Run-time error (9): Subscript out of range" error.

View 2 Replies View Related

Loop Within Array - Transfer Selection From One Slicer To Another?

Jan 8, 2014

I need to transfer selection(s) from slicer Country to Country1 (they cannot be connected due to workbook functionality).

User can make a single or a multiple selection in the country slicer.

So basically using CUBERANKEDMEMBER I got the output from slicer Country (in cell A1 for now) and used it as input in VBA for slicer Country1

ActiveWorkbook.SlicerCaches("Slicer_Country1").VisibleSlicerItemsList = _
Array("[01_Feed].[Dosage].&[" & Range("A1"]")

I have to use VisibleSlicerItemsList as it is an external data source (so cannot use ActiveWorkbook.SlicerCaches(Slicer Name).SlicerItems(Slicer Valuel).Selected = True/false)

Now, when user chooses 2,3 or more countries, they will be in cells A2, A3, A4... etc.

So, if the user selected 2 countries I would need to run a following code:

ActiveWorkbook.SlicerCaches("Slicer_Country1").VisibleSlicerItemsList = _
Array("[01_Feed].[Dosage].&[" & Range("A1"]", "[01_Feed].[Dosage].&[" & Range("A2"]")

Now, is there any way to loop this within the array, how many cells it should take?

For i = 1 to ..
code from above
Next i

won't work because then it only takes the last value, so I kind of have to loop it within the array.

View 2 Replies View Related

Loop Through Array In VBA To Refresh Pivot Tables

Jul 24, 2014

I'm hoping to automate some pivot table refreshes. I've got a dozen pivot tables on a sheet all with different numbers. I'm hoping I can write a code that loops through the pivot table names and runs the refresh. Here is the code as it is right now. I've essentially copied, pasted, and changed the name of the pivot table for the refresh.

I would like to create an array in vba (22,21,20,19,18...) that renames the PivotTable and runs the code.

sub Refresh ()
Dim pt4 As PivotTable
Dim Field4 As PivotField
Dim NewCat4 As String

Set pt4 = ActiveSheet.PivotTables("PivotTable22")

[Code] ..........

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved