VB Backward & Forward Loop

Dec 17, 2008

I'm writing a VB macro that will find the start time and finish time of a job and then work out the time it took to run.

So for example:
D E
09:53 wsp285A 09:53 wsp285A 09:53 wsp285A 09:53 wsp285A 09:53 wsp285A 09:59 wsp285A 09:59 wsp285A 10:06 wsp285A 10:06 wsp285A 10:13 wsp285A 10:13 wsp285A 10:20 wsp285A 10:20 wsp285A 10:26 wsp285A 10:26 wsp470a 10:29 wsp470A 10:29 wsp470A10:29 wsp470A 10:29 wsp470A 10:29 wsp470A 10:29 wsp470A

In the above I want to work our how long job 285A takes, I will need to find the first instance of the job by looping forwards through the data, and the last instance by looping backwards, then taking the last time away from the first.

The only problem is, I have no idea how to write this in VB!!

The job name is always in column E
The time is always in column D
I want to paste the time taken in for arguments sake in cell E1 of the current worksheet

View 9 Replies


ADVERTISEMENT

Running VB Code: Sheets Flicking Backward And Forward Many Times

May 8, 2007

when I run the code, because I have used many "Sheets("SheetNameHere").Select", the user will see the sheets flicking backward and forward many times and to avoid confusion, I don't want them to think "what the hell!"

Is there a way where I can still activate the sheets needed, but to somehow run all of "the code" in the background so all the user see's is maybe a status box or something which says "Please wait..."

View 9 Replies View Related

Count Cells Backward

May 11, 2007

I have a column with %'s. I need to start at the last entry and count back 30 rows and count the ones that do not = 100%.

View 2 Replies View Related

Finding 12th Month Backward?

Oct 17, 2011

I got a month APR 2011 now i need to find 12 month before month i.e MAY 2010 .

View 4 Replies View Related

Option Button Backward Selection

Jan 19, 2008

I have a workbook with 2 sheets. Sheet1 has a textbox and 2 option buttons named "north"and "south", and 2 command buttons named "send"and "retrieve".
Also a lot of other boxes, but they're not relevant.

I enter a unique number in the textbox, press one of the option buttons and press "send".
All data is now written in sheet2 in one row.

this all works ok.

Sometimes I need to change some data, so I enter the number in the textbox and press "retrieve". I get all the data back on sheet1, except the option buttons don't change correct. If on sheet2 the value = "north" I would like optionbutton1 to have the black dot and if the value="south" optionbutton2 should have the dot.

Now it's like they are on strike. they just don't react folowing the value of sheet2,collumn G, row "x".

View 9 Replies View Related

How To Carry Last Entry Forward

Apr 30, 2012

below fig 1 is a part of a worksheet we are using for Stock. The idea is to track stock write downs on a yearly basis. Where I am struggling is a formula to carry the stock balance and value forward if there has been no movement in a given year.

The enteries in green (fig1) colums "Stk Forw" & "Car Fwr" represent how I would like the info to look.

Is there a formula that could look for the last entry in "Stk In/Out" if the column "YTD to date" is empty and carry that value forward to the next row.

I Would also need a formula to sum the Total & Car Fwr colums as one total.

Fig 2 Shows the formula I am currenlty using.

View 1 Replies View Related

Generate Workdays For 1996 And Forward

Jul 11, 2009

i am trying to determine how to use the workday function to generate only workdays for 1996 and forward. Each year is listed in a separate column.

View 9 Replies View Related

Carry Forward Balance In Excel Using Template

Mar 12, 2013

I want to make a template in excel. Lets assume I have Opening Balance in A1 and closing balance in B1. How do I make template make new sheet and every time I make new sheets it should take the closing balance of the previous sheet as the opening balance and so on and so forth. But the very first sheet needs to have the opening balance as unlocked cell but the rest of them needs to be locked.

View 7 Replies View Related

Pull Forward The Dates By 3 Or 5 Working Days

Apr 15, 2009

I have a spreadsheet stating a date that my company will deliver a product by but due to a set of certain circumstances we need to pull forward the dates by 3 or 5 working days. Basically it needs to show the dates below but minus 3 days unless this includes non-working days (i.e. weekends)

01/01/10
02/01/10
03/01/10
04/01/10
05/01/10
06/01/10
07/01/10
08/01/10
09/01/10
10/01/10

View 3 Replies View Related

Format To Bring Decimal Point Forward

Aug 22, 2008

Is there anyway to be able to bring decimal point forward without affecting the numbers using any formatting, which will still be there even after refreshing the query.

For example, 0.0531 to 53.1

View 9 Replies View Related

Roll Sequential Numbers Back & Forward

Jan 28, 2008

I am running a worksheet that runs through 4 week periods.

Example: 10.1 10.2 10.3 10.4 11.1 11.2 11.3 etc.

I wish to insert a formula that will roll forward or back this data when required.

I have no problem rolling whole numbers & dates.

Iam using Excel 2000.

View 7 Replies View Related

Formula To Extract All Characters After A Certain Number Of Forward Slashes From The Right?

Apr 9, 2014

I'm working with a large list of items of varying length. A sample worksheet is attached. I need to do the following:

1) If the characters after the final forward slash from the right are of the pattern "tttxxx" (where "t" is text and "x" is a number/digit), then return all characters to the right of the final slash, including the slash itself:

Y:/Series/hun/hun109 ----> /hun109

2) if the characters after the final slash from the right are not of the pattern "tttxxx", then return all characters after the second slash from the right, including the slash:

Z:/Series/crd/crd409/editorial ----> /crd409/editorial

3) if there are less than 3 backslashes in the item, return a blank.

View 3 Replies View Related

ListBox: Insert New Columns List Moves Forward

Feb 2, 2009

I have 2 Listbox in Sheet3 & lists in Sheet1 & Sheet2 in columns A:A. When I delete columns in this Sheets or insert new columns List moves forward i.e. But I need The ListBox show allways List in the Columns A:A.

View 4 Replies View Related

Calculating Current Cover Based On Forward Requirements

Nov 17, 2007

I have drawn up a simple summary to show what I am trying to achieve: ...

View 9 Replies View Related

How To Subtract / Add Days / Months Using Borrow / Carry Forward To Previous Cells

Dec 8, 2013

I have subtracted two dates from B2 & B1 using DATEDIF() Function and the results are available in (B5) Year, (C5) Month and (D5) Days respectively. Now the problem is how to Subtract, Add days & Months using borrow, Carry forward to the previous cells (I need formula, function for the above). I have to take 30 days from month ie in C5 if the days (D5

View 1 Replies View Related

Move From Seperate Columns On Sheet2 To One Column With Forward Slashes "/" Between Sheet3

Jan 11, 2010

I have three columns (9, 10, & 11); text, currency, and text and I am trying to move them from seperate columns on Sheet2 to one column with forward slashes "/" between them on Sheet3. The attached code does this, however I lose the dollar sign and commas.

View 4 Replies View Related

Clear Data Depending On User Input And Move Cells Forward Without Deleting Data Table

Oct 25, 2012

I have an month input in cells B2 (user can enter values from 1-5)

I then have a data table that has month 1,2,3,4,5 running across range G9:K9. the data is held in range G10:K19.

So if user types in 4 in B2, what should happen is that months 1,2,3 and 4 the data for these months should be cleared and data in month 5 moves forward into month 1.

So basically, anything left of the month entered is B2 should be cleared and replaced with anything right of the month in B2.

1
2
3
4
5

£11
£133
£29
£193
£100

[Code] ........

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

Loop Through Multiple Files And Call Macros (but Unable To Loop)

May 14, 2014

Macro which loops through a number of files and calls the same macro in each of them. Unfortunately when I add "Application.Run..." to the code, it no longer loops through the process and instead stops after updating the first file in the loop. If I remove the "Application.Run..." code and add any other code, the loop works fine and it continues through the process repeating all the steps for each file found.

Why it stops after one file when using "Application.Run..." to call the macros?

NB I have a list of path and file names starting in row 8 of columns A and C. Each file in the list has a macro called UpdateS1 and promoupdate1.

Sub C_Run_Loop_Macro()
Dim lastRow As Long
Dim i As Long

[Code]....

View 4 Replies View Related

Store Row Number Within Loop And Delete All Stored Rows After Loop?

Sep 11, 2013

I have working code that returns a row number within a for loop based on parameters I set.

Each time the for loop runs I would like to store this row number, then after the loop has finished, delete all stored rows.

Code:
for rowNum = 1 to x (some variable end row number which I already have worked out using End(xlUp).Row)
if x = y then
*storedRow = rowNum
end if
next rowNum
*

Lines with a * are the bits I can't work out. I've been trying to understand arrays by reading posts on what other people have done, but I can't fit (or fully understand) the reDims, or reDim preserves into my code. I've seen what appear to be quite complex ways involving uBounds and LBounds, but unfortunately I can't see how to use them.

All I want is to simply keep adding a row numbers to a variable, (i.e. row 2, 5, 20, 33, 120, etc) and then delete those specific rows.

View 4 Replies View Related

Loop Through Cells And Ranges Reverse Order With Backwards Loop

Aug 30, 2006

I am looping through each cell in a range and I would like to loop in reverse order.

Dim CELL As range
Dim TotalRows As Long
TotalRows = Cells(Rows.Count, 1).End(xlUp).Row
For Each CELL In Range("C1", "C" & TotalRows)
CELL.Select
'Code here to delete a row based on criteria
Next

I have tried:

For Each CELL In Range("C" & TotalRows, "C1")

and it does not make a difference. I need to loop in reverse order since what I am doing in the loop is deleting a row. I am looking at a cell and determining its value. If the value is so much, then the row gets deleted. The problem is that the next row "moves up" one row (taking the pervious cell's address) and therefore the For Each Next loop thinks it has already looked at that row.

View 7 Replies View Related

Copy Cells In Loop Based On Loop Increment Being Multiplied

Feb 7, 2008

I have some numbers in a column that I need to copy 12 times (each one) into another column. The problem is that I got like 200 records that will be converted in 15000 aprox. I've uploaded an example of what I need,

View 3 Replies View Related

Loop Through Index Worksheets Using For Loop And Select Clause

Nov 4, 2013

I have a workbook that contains, say, 50 worksheets: the first two worksheets summarise the data and are static in that they don't move position. However, the next four worksheets contain certain data for any given month. Each time a new month comes along, say, November, I insert four new worksheets after the two static ones as a result October's four worksheets are simply moved down the line in terms of worksheet order.

I need a macro to refer to the first six worksheets only (not the other tabs). I opted for index referencing for each worksheet, ie one - six. Now within these six worksheets in any given month, I need to sort the data by a certain column. The problem: in sheets 1,4,5 and 6 I need to rank by column E, but in sheets 2 and 3 I need to rank by column C. I have stepped through the code, which works for sheets 3-6, but doesn't seem to refer to sheets 1-2.

Sub WorksheetLoop()
'
' Loop through an indexed number of worksheets; _
' & this ensures that the worksheet range is dynamic _
' and is able to adjust when new sheets are added/removed, etc.
'
'Dim ws As Worksheet
Dim i As Long
Dim ws As Worksheet

[code]....

View 2 Replies View Related

Avoid Changing A Loop Counter Within A Loop?

Oct 24, 2009

I've worked on a solution for this thread (http://www.excelforum.com/excel-prog...-automate.html) but have been mentally challenged with how to avoid changing the loop counter in one of the loops I have used to resort an array of file names from the getopenfile dialog.

The aim of the shown code (see post 12 of the above link for attached file) is to check if the file containing the macro is included in the array returned by getopenfile while sorting the array of file names, and if so, moving it to the end of the array for "deletion" by redimming the array to exclude the last item. This problem of the open file being selected in the dialog may never arise, but... as the OP's request in the other thread was to allow two-way comparisons between numerous files, I've considered it likely enough to test for.

Here's the code I have settled for esp between the commented lines of hash symbols, which does change the counter (see the commented exclamation marks), but prevents an infinite loop (on my second try!) by using a second boolean flag of "HasCounterBeenChanged". Is there a better way of doing this? Or, alternatively (not in my thread title), is it possible to prevent the active file being selected through one of the arguments in the getopenfilename method?

View 3 Replies View Related

Copying From One Loop To Paste Into Another Loop?

Aug 27, 2012

I am working on some code that loops through a column of number values. Whenever it encounters a number value and a blank cell in an offset column, it places that number value into an offset cell (forming a separate column to be compared to another column in a separate sheet). I would like to take all the values in that new column and begin placing them in a new column in a separate sheet adjacent to another table. Most of the time, these values should match the adjacent values in the separate worksheet. However, if they don't match, I would like a new row to be created for that mismatched value.

For example. This is the first worksheet. So far, my macro loops through the column with rows 1-5. It looks in the offset cell(0,2) for Isempty value and then places that value into the offset cell(0,6)

text
1
text
text

[Code]....

View 5 Replies View Related

For Each Loop To Delete Row W/ Value (Loop Backwards)

Aug 2, 2007

For Each loop can be instructed to loop starting the bottom of the range. I know that a For To Loop can handle looping from the bottom up,

Sub Filterout()
Dim c As Range
Dim rng As Range
Dim i As Long
Dim lrow As Long
Dim counter As Integer
lrow = Cells(Rows.Count, 3).End(xlUp).Row
Set rng = Range("c2:c36")

For Each c In rng
If Left(c.Value, 1) "~~" Then
c.EntireRow.Delete
End If
Next c

View 9 Replies View Related

Nested Loop. Inner Loop Not Running

Nov 30, 2006

i have a problem with a nested loop:

it seems like the first instance of the code is running the way i want it to run, but when it starts with the second instance, it does the first search and copy, but it seems like the nested loop is being ignored.

am i doing something wrong?

dan
==========================================================
Thanks to Aaron Blood for the find_range function. i also poached the lastrow function from somewhere on ozgrid, but I cant remember the name of the poster.
==========================================================

Sub new2()

Dim Org_Area As Variant
Dim Item As Variant
Dim Copy_To1 As Variant
Dim Cell_Ref As Variant

r = 1 ..................

View 9 Replies View Related

Do...Loop Error :: Loop Without Do

Dec 17, 2008

Can't seem to figure out why my Do Loop keeps giving me an Error of "Loop without Do".

View 14 Replies View Related

Loop Inside The Loop

Apr 28, 2009

I have got a loop which is working fine but now i need another loop which will run till the end but need to repeat itself as soon the column x become 1 the highest number would be 3

here is my main loop A1 = 5000
and second loop need to run inside the this loop

Sheet1.Activate
i = Range("A1")

For b = 1 To i
If Cells(1 + b, 3).Value = "P" Then
Cells(1 + b, 29).Value = 1
Else
If Cells(1 + b, 3).Value = "S" Then
Cells(1 + b, 29).Value = 2
Else
If Cells(1 + b, 3).Value = "C" Then
Cells(1 + b, 29).Value = 3
End If
End If
End If
Next b

View 9 Replies View Related

Endless Loop Within A Loop

Oct 28, 2006

I have loops working in other loops. The macro is almsot working well. It does the calculation i want but it fails to stop a loop, because of that, the macro can't run the next main loop (c), which is to move to the next cell where the calculations must be run.

I attach a file. the troubleshooting macroation is Sub Itiration.

The code of this macro are bellow. Basically, the loop using d as counter run into an endless loop. I don't how to stop this loop without affecting the results which are calculated correctly.

Sub Itiration()
Dim CurCell As Object
Dim TempSum As Double
Dim d As Integer

For c = 3 To Cells(3, 4)
If Cells(11, c) > 0 Then
For i = 1 To Cells(10, c)
Do

View 9 Replies View Related







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