Loop Sequential Variables

Sep 29, 2007

I have variables 1-6 like the following:

dDDDD1 = Format(d1, "dddd")
dDDDD2 = Format(d1, "dddd")

They correspond to a date from a cell and I just format one for "Monday" through "Saturday". In another module I'm opening a file that has worksheets named "Monday" through "Saturday" as well. I need to do the same thing to each of these sheets so I'm trying to setup a For/Next loop. I'm assuming you can't put a variable to a variable as I keep getting 'variable not defined' when I try to insert 'i'? Or am I just going about this all wrong?

For i = 1 To 6
Workbooks.Open ("J:AcctMgtITrepADIinf-v2-WE0922.xls")
Sheets(dDDDD & i).Unprotect Password:="hownowbrowncow"
Sheets(dDDDD1).Columns("C:E").Insert Shift:=xlToRight
Sheets(dDDDD1).Columns("B:B").TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=True, Other:=False, FieldInfo:= _
Array(Array(1, 1), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
With Sheets(dDDDD1)
Set RngCol = .Range("A1", .Cells(Rows.Count, 1).End(xlUp))
End With
ConcName = "=B1&"", ""&C1"
LastRow = RngCol.Rows.Count
Sheets(dDDDD1).Range("$E$1:$E$" & LastRow).Formula = ConcName
Next i

View 2 Replies


ADVERTISEMENT

Copy / Drag From Sequential Column To Non-Sequential Ones While Retaining Sequence

Jan 29, 2014

I have a form made that needs to copy a value from another sheet. The Form is 10 rows 5 columns and and in format for easy print. On sheet2 I have a column where each row is filled with a name.

I need to put this name into sheet1, so in the the appropriate cell I put =Sheet2!B2 and it gives me the value (name) from the other sheet.

Then I want to copy the form bellow the 1st one so that I have the same form but with the next name, which means I want =Sheet2!B3 to appear when I copy, but since my form is 10 rows when I copy it the formula copies to =Sheet2!B12 instead of B3.

I need to make close to a thousand of this forms ready for printing and I would like to avoid having to manually set the formula for the next cell.

View 3 Replies View Related

Loop Through Variables

May 31, 2007

This has sort of been asked before

Improving a vba function argument check loop

but is there a way to loop through a series of variables like var0...var9? You can obviously loop through and make a set of strings with the right names,

Dim I As Integer
Dim Var As String
For I = 1 To 5
Var = "Var" & I
Next I

Is there a way to use the contents of a string variable to call a variable with the same name as contents of the string? or somehow concatenate the a string with a number like
array[i]=var.[i]?

View 9 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

Define Variables In For Loop?

Jul 8, 2014

I am trying to define my variables with a for loop and if I run the code to the line after the first variable is defined, it shows that the variable is equal to the appropriate value, but after the for loop is done all of the variables are empty.

[Code] ......

View 5 Replies View Related

Loop Find With Variables

Nov 22, 2011

I have a process where I need to search for multiple customer numbers and delete line associated with them.

My question is how do I create this process to run in a loop going through all 10 numbers?

View 1 Replies View Related

Loop With Changing Variables

Oct 16, 2007

i have set up some test script below!

i dont know if it is possible but can you concatinate two variables i.e in the example below can i move from Sum1 to Sum6 using the intiger stored in i as the end of the sum variable

Sub Sum()
Dim i As Integer
Dim Sum1, Sum2, Sum3, Sum4, Sum5, Sum6 As Integer
Dim Ltr As String
Dim Sum As String
Sum = "Sum"

Sum1 = Range("B5").Value
Sum2 = Range("C5").Value
Sum3 = Range("D5").Value
Sum4 = Range("E5").Value
Sum5 = Range("F5").Value
Sum6 = Range("G5").Value

For i = 1 To 6
MsgBox "The value in cell " & i "is " & Sum & i
Next i

End Sub

View 9 Replies View Related

Cumulative Sum In Loop Using Variables

Apr 6, 2008

I'm having difficulty with concatenation and the use of a string variable. On my attached spreadsheet I have a row called Must Fund Tasks. The binary variable in the cell is entered by a selection on a user form. If the value of the cell is "1" then that particular task must be funded. The code I developed forces solver to keep the binary value of 1 in that particular cell when looking for the optimal solution. This same row of binary variables is the row of values that I have solver change to find my optimal solution.

My problem is that I have another set of contraints based on mutually exclusive tasks. If there is a binary value of "1" in at least two of those cells then only one of the tasks may be funded and they are said to be mutually exclusive. In other words, if the user form indicated that tasks 1 and 5 were mutually exclusive then the binary values are Task1=1 and Task2=1 and the constraint would be Task1+Task2<=1. The code I've written looks for a value of 1 in the Mutually Exclusive row and if it finds one it adds the name of the corresponding "Must Fund" cell 4 rows above to a set called ExclusiveSet. ExclusiveSet is defined as a string and I'm having trouble with the concatenation, I keep geting a "+" out in front because of the intial loop when ExclusiveSet="" ( it returns "+$F$29+$H$29"). I'm also not sure if Range("CalcsStartcell").Offset(I + 15, 3).Formula = "=ExclusiveSet" is the appropriate way for me to return the value of the ExclusiveSet in the desired cell.

Sub constraint()
Dim p As Integer, CalcsStartcell As String, I As Integer, T As Integer
T = 7
I = 5
CalcsStartcell = "C16"

'setting Mutually Exclusive constraints
With Worksheets("Sheet1").Range(CalcsStartcell)
For p = 0 To T - 1
If .Offset(I + 12, p + 1).Formula = "1" Then..................

View 7 Replies View Related

Reset Variables For Each Pass Through For Loop

Jun 27, 2014

I am having trouble defining a variable in a For loop. When I run the loop the first time everything seems to work fine, but when the loop goes back through the second time it carries its previous value with it. Here in lies the problem if the variable is supposed to be empty (not assigned a value). So, for example: 'Variable' in the code below may or may not be given a value depending on the conditions in the For i loop. If it is given a value then 'Variable' will still have that value on the next pass through the For j loop. And if none of the conditions are met for the If statement in the For i loop the second time through the For j loop, it should be an empty variable, but instead the code is reading it as having a value (from the previous pass through the For j loop).

[Code] .....

I have tried using:

[Code] .....

After the For j line, and instead of using:

[Code] ....

I tried using:

[Code] ....

and I've tried:

[Code] .....

I get an Object error with either line I use. I just want to be able to reset the variables each time through the For j loop so in the case of an empty variable, it doesn't try to calculate based on the previous value.

View 6 Replies View Related

Loop Range Using Variables For Rows

Dec 16, 2006

I need to write a FOR... Next loop that will loop through a range of rows, select the same cell range on each row, perform a task, then advance to the next row. I can't seem to figure out how to substitute the loop counter for the row index. For example:

For counter = 1 To 100

Range("B(counter)","F(counter)").Select
ActiveCell.FormulaR1C1 = "1"

Next counter

View 3 Replies View Related

Loop Through Range & Use Cell Values In Variables

Aug 30, 2006

I have 2 worksheets. The first sheet has data of which some needs to be copied to a second worksheet. The trigger is a value found in column E. If a match is found, then a copy statement needs to be built. The values in F, G & H are the values to be used in the copy statement. The content of cell H may be numbers or letters or both.

What is the correct format of the copy statement?

Dimension all variables
Dim RowPointer As Long
Dim wbContrib As Workbook
Dim wbMaster As Workbook
Dim SheetName As String
Dim target_sheet As String
Dim target_cell As String
Dim Target_value As String
Dim CellAddr
'
' Initialize variables
Set RowPointer = 1
Set wbMaster = “Master.xls”
'
'******************************

View 9 Replies View Related

Locating Important Columns In A Table Of Raw Data - Setting Variables Using A Loop

Feb 22, 2012

I need to be able to locate some important columns in a table of raw data (the column locations are not fixed).

I would like to identify the locations (based on the heading values in Row 1) and store them as Public variables. The Match function works fine for this, however I'd like to make a simple loop to set these variables (opposed to repeating the function for each).

In the example below, I can't figure out how to reference "List1(Count)" as the name of the variable I'm trying to set.

Code:

Public Field1 As Long, Field2 As Long, Field3 As Long 'The column numbers will be stored here
Sub FindFields()
Dim List1(3), List2(3)
Dim Count As Long
'Public variables (declared above)

[Code] ......

So after running FindFields(), the Test1() macro should give "1 - 2 - 3" (for example) as the locations of the fields in Sheet1. But currently this doesn't work.

View 2 Replies View Related

Unzip Code - Works Without Variables, Breaks With Variables...

Feb 5, 2009

Unzip Code - Works without Variables, Breaks with Variables.... This has been driving me bananas...

I have the

View 2 Replies View Related

Using If To Sum() Non-sequential Numbers

Jan 23, 2009

I need a formula to add data in it's respective column, only if the month and year match.

The columns of data will be very long, thousands of lines possibly.

So, basically, in this example.

in O1, if the the data in the columns below match the month(M1) and year (N1), then sum those variables.

View 10 Replies View Related

Using For / Next With Sequential Variable Name

Jan 10, 2013

I'm just looking to step through some variables using for/next

variable1 = 2
variable2 = 7
Variable3 = 9
Variable4 = 15

For xxx = variable1 to variable4

'all sorts of fun code here

Next xxx

-obviously this doesn't work, it steps from variable1 right to variable 4....need a way so the code includes variable 2 and 3.

View 6 Replies View Related

Sequential Months

Feb 8, 2010

I am creating a budget worksheet for non-technical users. They choose a starting month from a drop down menu (already created). I want the remaining 11 months to automatically fill in to the right (in a row). I have created a macro (initiating autofill) that requires them to click the button after they choose the starting month but this copies the drop down menu & Input message from the Data Validation I used to guide them initially.

View 9 Replies View Related

Sequential Numbering

Oct 25, 2009

I have a workbook with two worksheets. Worksheet #1 is a form that will be populated with data and saved as a new worksheet, then cleared and used repeatedly as a master form. Worksheet #2 is a log / register of the unique forms completed and saved from the master each time. I need to assign a unique sequential # to each form when it is saved and record this number in a column on Worksheet #2 (the Log). I am using some macros for the copy work but struggling with the auto-numbering of the forms when completed and saved.

View 3 Replies View Related

Sequential Tab Renaming

Apr 10, 2007

Is it possible in Excel to automatically rename all the tabs of a workbook in one move in a sequential format - eg renamimg 52 weekly tabs Week 1, Week 2, Week 3 etc.

View 2 Replies View Related

Sequential Alphanumeric Entries

Jun 19, 2014

I'm trying to create a single column of stock bin codes for eventual conversion to barcodes. The bin codes run like this:

A1A
A1B
A1C - etc. to A1H, then the sequence starts again with:
A2A
A2B
A2C etc. up to A6H, when the 1st character changes to B and the sequence starts again

This needs to continue until the sequence reaches Z6H

How to do this without having to enter each code manually?

View 11 Replies View Related

Sequential Numbering With Gaps

Nov 10, 2007

I have a column in which I enter a date, and an adjacent column which automatically enters a sequential number, using ...

View 10 Replies View Related

Sequential Fill Down Only One Cell?

Jul 20, 2014

I'm making a Purchase Order generator for work. Essentially, the main screen has buttons and the user selects the company, job number, their name etc. They click 'Generate' and it will great a brand new excel file for them with all the correct codes, ready to populate and send to a client. In the main sheet, we also have a master list showing every purchase order made to date. This is where I am currently stuck. I will have many more questions on the way. This is my first program so very new!

Lets say we have the following in cells A1 and A2. The rest is blank:

REQ0001
REQ0002

[Code] .......

View 3 Replies View Related

VBA - Printing Sequential Invoices?

Dec 4, 2007

I have written some code for a friend of mine, but I cannot test it because I currently don't have a printer attached to this computer. I am confident that it will work, but I would like a second set of eyes to confirm that I havent missed anything.

I have a userform with two textboxes. One of them asks how many copies of the invoice to print out, and the second one asks what invoice number to start with. THe invoice numbers are recorded in Cell I1.

[Code]......

Also, for the future, in a situation like this, is there anyway to test if the code would work without a printer? I tried substituting printpreview, but my computer locked up.

View 14 Replies View Related

Sequential Numbering Macro?

Feb 28, 2014

I have a large sheet (currently some 5,000 rows and growing) where each row is allocated a Unique Reference, however that unique reference is based on two criteria, 'Region' and 'Type'.

There are four 'Regions' and three 'Types' across the whole sheet (see attched sample).

Because of the ever increasing number of entries and the fact that the sheet may be sorted so the unique references won't always appear in sequential order, I am looking to try and find a way for the unique refrence for 'new entires' to the sheet to be generated automatically, based on entires in other columns. The sheet structure is relatively simple, with 'Region' shown in one column and 'Type' in another (again, see attached sample).

The unique references adopt this structure - 1st letter of the region (N, S, E or W for North, South, East or West), followed by 1415, followed by the first 4 characters from the 'Type', (REGI, NATI or COUN for Regional, National or County) followed by a sequential 5 digit number 00001, 00002, 00003 etc.

resulting in for example N1415REGI00001 or W1415COUN00012 and so on.

Because there are thousands of entries, I need an automatic way for the unique reference to be generated, ideally once both the 'Region' and 'Type' fields are populated, so the macro (or whatever method works best) will automatically determine the previous highest number for the relevant series and automatically add the next number for the new entry, based on the above criteria.

I don't know if this is possible with a macro or whether there is an easier formulaic way to achieve this?

View 14 Replies View Related

VBA: Printing Sequential Invoices

Dec 4, 2007

I have written some code for a friend of mine, but I cannot test it because I currently don't have a printer attached to this computer. I am confident that it will work, but I would like a second set of eyes to confirm that I havent missed anything.

I have a userform with two textboxes. One of them asks how many copies of the invoice to print out, and the second one asks what invoice number to start with. THe invoice numbers are recorded in Cell I1.

View 11 Replies View Related

SUMIF With Sequential Criteria

Jul 31, 2007

In the formula (range, criteria, sum_range), I have a fixed range and a fixed summary range for each column, i.e.: ($F$3:$F$805, "criteria", O$3:O$805).

HoweverI am trying to sum up units by income level (columns D, E, and F) using information from elsewhere on the sheet. I am doing this for each city, which entails changing the criteria for all of the cities I am using three times (once per column).

Is there a simple way to autofill the criteria? They are just names of cities, all in the same column, COLUMN B. Or do I have to type each individual change?

View 10 Replies View Related

Sum No-sequential Cells But Omit Zero

Dec 31, 2009

I have four cells that I want to sum: =SUM(D3,H3,L3,P3)

I want to EXCLUDE the cell from the sum if the preceeding cell (C3,I3,K3,O3) has a value of "0".

View 9 Replies View Related

Sequential Numbering Macro

Sep 3, 2006

I need a macro that will number a cell (A1 for example) starting with the number 1, and another cell (A2) with the number 2, then back to the first cell with 3, then back to the latter cell with 4 and so on.

View 9 Replies View Related

Adding A Sequential Number

Jan 26, 2007

You will probably find this very easy but I am having all sorts of trouble making it work as I want to! Basically I need to do the following procedure...

1) Open an Inputbox to collect an eight digit number
2) Insert a column in A:A
3) In A1, enter a col header (URN)
4) In A2, enter the number that was collected in the inputbox
5) Enter sequential number from A2+1 to the last row

Ideally, this would be randomised, so after stage 2 do RAND(), sort, and clear contents, but if I can get the main part right I'm sure I can work that out!

View 3 Replies View Related

Add Sequential Numbers To Range

Aug 17, 2007

I have created two names within column A (ie: Insert/Name/Define)

in cell A1 I've named StartA01
in cell A5 I've named EndA05

I would like to create a sequential number within this range via script, whereby when new rows are inserted, the script will update the order.

eg:

begin with:

A01
A02
A03
A04
A05

3 rows inserted will update to:

A01
A02
A03
A04
A05
A06
A07
A08

View 9 Replies View Related

Loop Within A Loop (repeat The Loop Values)

Mar 31, 2008

With Sheets("regrade pharm_standalone")
For Each r In .Range("standaloneTerritory")
If r.Value = "X101" Then
r.EntireRow.Copy
Sheets("X101").Range("A1").End(xlDown).Offset(1).PasteSpecial xlPasteValues
End If
Next r
End With
-------------------
I need to repeat this loop for values from X101 to X151. In all cases, the sheet name is equal to the value I'm looking up (eg: value = X102 goes to sheet X102).

I have a named range called 'territories' that contains the list of X101 -> X152.

I'm hoping to make the code perform the loop for each of the territories without my having to copy & paste and change the 'X101' 51 times as this would seem a rather silly thing to do!

View 9 Replies View Related







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