I want to organize the data by broker then by security, I created the following code to do the looping...but it stopped loop and generated information for one broker....Do you know what is wrong with my code?
I also want to sum the results of cell (A,7) based on broker...basically I want to insert a new row to sum the results of one broker, before going to the other...how should I do that also?
Sub OJOM1()
Dim A As Integer Dim B As Integer Dim Broker As String Dim OJOMM As String
A = 2
'Do While Worksheets("historydata").Cells(A, 1) <> "" B = 1
Do While Worksheets("BrokerList").Cells(B, 1) <> "" If Worksheets("BrokerList").Cells(B, 1) = Worksheets("historydata").Cells(A, 6) Then '= Worksheets("BrokerList").Cells(B, 1) Then Broker = Worksheets("BrokerList").Cells(B, 1) 'MsgBox Broker Do While Worksheets("historydata").Cells(A, 1) <> "" If Worksheets("historyData").Cells(A, 6) = Broker And Worksheets("historydata").Cells(A, 2) = Worksheets("MarginReq").Range("B4") And Worksheets("historydata").Cells(A, 3) = Worksheets("MarginReq").Range("B5") Then Application. ScreenUpdating = False Worksheets("historydata").Cells(A, 6).copy Sheets("MarginReq").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) Application.CutCopyMode = False Application.ScreenUpdating = True
Application.ScreenUpdating = False Worksheets("historydata").Cells(A, 7).copy Sheets("MarginReq").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0) Application.CutCopyMode = False Application.ScreenUpdating = True End If A = A + 1 Loop End If B = B + 1 Loop 'A = A + 1 'Loop End Sub
I am doing wrong here, the code seems to keep looping. I broke out of the search and its found the correct information and copied the correct rows, though looped and did it again, and again, and again,
The code below first asks a user to input a weekending date (which must be a Saturday). The value of the input box goes to cell C1 of my spreadsheet. That part works fine. I also have a function in Cell G1 with the function:
=TEXT(C1, "dddd") I don't know if this is the best way to test for a Saturday but it is what I have,
Where is goes bad is if the date is not a Saturday. I have a loop to force a new date install via a input box but it won't update C1 with the inputed data to recheck for the Saturday value. Below is the whole code I am working with...
Dim aa As String Dim bb As String
If Range("C1") = "" Then Do While bb = "" bb = InputBox("Please Enter a Weekending Date!") Loop Range("C1").Value = bb End If If Range("G1") "Saturday" Then Do While aa "Saturday" aa = InputBox("Weekending Must Be a Saturday. Please Enter a New Weekending Date") Loop Range("C1").Value = aa End If
the following code should determine whether the searched value can be found in more than just one row and than enlist certain values from each of those rows in ComboBox4 using a loop. Then I have a second macro which would assign appropriate values from a Sheet to other text boxes whenever one changes the value of the ComboBox4:
Private Sub ComboBox2_Change() Dim vFind Dim Firstaddress Dim rFound As Range Dim wsName As String Dim SrchRng As Range wsName = Me.ComboBox1.Value With Worksheets(wsName) vFind = UserForm2.ComboBox2.Value Set rFound = .Range("B1") Set SrchRng = .Range("B:B") Option Explicit End With...............................
While trying to run the first macro an Error pops up saying that a variable within the loop is not set. I've got no idea how to fix it
I have data in a pivottable which I want to compare with another table. The lastcolumn+1 of the pivottable needs to get data from another table. I have this for an example:
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!
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
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.
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.
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,
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
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?
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)
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
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
Because I am pulling data from external aplication, so the 0 is fix in a row/column.. I will need to get the row/column for the whole "01" and not only "1".
Is it possible to write a cell formula (not a macro) to loop through a range of cells and test for a value? Something tells me that I need to use the "Offset" function.
How do I continue to loop through the last row and get the values to 3 differrent text boxes?
If I remember right, I think the command is Offset, 1 to go to the right one cell correct?
Sub CommandButton1_Click() '("PowerAnalysis").cells(Row, 3).Value = textbox1.Value 'Worksheets("PowerData").Cells(Row, 3).Value = TextBox1.Value Set WkSht = Worksheets("PowerData") LastRow = WkSht.Range("A" & Rows.Count).End(xlUp).Row
WkSht.Cells(Row, 1).Value = TextBox1.Value
'LastRow = r 'r = ActiveCell 'Dim r As Long 'r = ActiveCell.Row 'UserForm3.Show
'WkSht.Cells(Row, 3).Value = TextBox1.Value UserForm3.TextBox1.Value = r
End Sub
This code is wrong, but how can I get the first three records on the last row to display in three textboxes on UserForm3 titled TextBox1, TextBox2 and TextBox3.
Norie may be right, I may not have to even think about using repaint.
I have created a spreadsheet used for timber design. The spreadsheet calculates whether a specified size of timber column will support a specified load under certain conditions.
The various conditions include, load duration, service class, strength class and limit states.
Ok at the moment the user specifies the load and length of the column, then chooses a size of timber and sets the conditions mentioned above. Once this has been done the calculations i have put together on another sheet, work out whether the size of timber can support the specified load.
It is important to know that the answer for the final strength formula of determining the strength of the column should be equal to or less than 1. If this is the case then the column is ok, if the answer is larger than 1 then the column isnt safe.
Also at various points within the calculation certain checks are required to make sure certain design values satisfy certain criteria. If they dont then a new size of timber sould be tried.
What i would like to be able to do is use a loop so that the spreadsheet will use differing sizes of timber and calculate the values that satisfy the criteria and eventually find the size of timber required. The final answer of the strength calculation should be as close to 1 as possible but not over.
My code is supposed to generate figures to plot the changes in a riverbed profile with time. At time zero, there is a main subroutine that goes through a number of Subroutines and iterations before ending. At time t, I have another main subroutine which is slightly different but would go through most of the subroutines of tine zero. I want the code to go through for time t=0, display the values and then go through the other loops as well, displaying the values for each loop. I thought I knew what I was doing, but the displayed results showed reasonable results for the first (time zero), but the others were just replicas of the same thing. Is there anyway I could use variables with vectors i.e patty(j,i), where i could run the loop for i, and then do Next j.
I have the below code which converts a range to PDF and saves it on our network drive. I would like to change my code to a loop so I don't have to do so much typing. There are 68 rows between each range.
I am trying to code something that will loop through a given set of columns. I know that if I say "For each C in R", that would mean, looping through each cell inside the Range "R", but what I want is something like this:
VB: Dim rzRng As range, rzSmallRng As range Set rzRng = Union(range("A:A"), range("C:C"), range("F:F"), range("AB:AB"), range("AS:AS"))
For Each rzSmallRng In rzRng statement here... Next
(I have a total of 30 columns that I need to put inside that Union function) . And then loop through the range as a whole set (not though each cell of that range).
I also tried the following code:
VB: With Union(range("A:A"), range("C:C"), range("F:F"), range("AB:AB"), range("AS:AS")) statement here.... End With
But it ended up executing the code in Range"A:A" only.
I am looking to create a loop in a ListObject object that does calculations depending on the value of the current certain row in a column. This is the code I have so far:
[Code]....
I am having trouble with the loop; as you can see, the nested for loop will go through all the 'weight' in the column before going to the next 'grade'. I just want the loop to reference the same 'weight' that the 'grade' is on and move on. But I am not sure how to reference each 'weight' as I progress through each 'grade' in parallel.
I am aware that I can do this with regular cell references:
[Code] ......
but I am more interested in learning on how to work with the ListObject class.
so i've got a spreadsheet that i'm working on that i'm doing some automation for and i'm not sure where to go from here. i don't know too much about coding, but pick up a little here and there.
so what i have is 2 spreadsheets that i'm using to compare data and copy and paste the information found. there is a list of data in column E that i am copying and pasting into the "timestamp log" which has a macros that search for a variable in that workbook, if the variable is found the cell is copied. then "advisor info1" is activated and pasted in column H.
now i'm trying to avoid having to write the below coding for each and every cell in column E that has data to be found. is there a way to loop the process until a blank cell is found? like to have it search cell e2, e3, e4, e5... etc until it hits a cell with nothing in it? sometimes i have over 1000 cells in column E that i need to search through and trying to copy and paste out the below information 1000 times is very tedius and a waste. anyone have any ideas?
i'm not sure if i explained it clearly enough, let me know if you need a little more clarification .......
I have a formula in cell A1 and text in either cell B2 or C2. This text continues down the rows until there is no text in either columns B or C. I wish to copy the formula in A1 into A2 and then continue copying down column A until both cells in column B and C are empty. What is the excel VBA code?