I need to copy the value from cell Z18 and then use the function 'paste values' to input the data in cell B24.
Having done this I need the sheet to recalculate and generate a new set of random numbers. I then require the new value in cell Z18 to be copied and pasted in the next row of column B, cell B25.
I need this process repeating for 10,000 iterations so that the range B24:B1023 is filled.
Here is my code, it will recalculate cell Z18 and return the value in cell B24, but will not offset down one row and loop.
I am trying to derive a formula to calculate a final value of an account.
The accounts initial value is say $2000. After 1 trade, I either lose 2% of the account value, there is 20% chance that may happen, or I have 80% chance of the account increasing by 0.8%. The win or loss is either added or subtracted to the original account.
The second trade has the same probability of win loss, but the percetages are based on the new account figure.
What is the account value after 'n' trades?
I originally started by using the compounding interest formula, after calculating an expectancy.
Has ever created a spreadsheet that used Monte Carlo Simulation?
I've been able to create one that works using the random number generator in conjunction with discrete probability distributions - that's fairly easy, just assign a probability to each discrete value in the distribution and then decide whether or not to select it using a randomly generated number.
However, I want to perform a Monte Carlo simulation that uses a continuous (not discrete) probability distribution, but how I would use the random number generator to then select a value from the distribution based on its probability of occurance.
I have a number (>100) of excel workbooks (consistent format) on a server and I am trying to create a master spreadsheet with links to specific cells. I started using formulae based on Concatenate and Indirect functions but always had to use F2 & F9 to get a result. I am now working on a macro to build semi dynamic links, I am some way there but need some expert help please.
In Col A I have the path and file name for all my source files - I have used the Filename *.xls & FoundFiles for this.
In Col B is my specific file name(s) extracted from Col A using an If , Len and Text function.
My macro declares variables; File = Range (“B#”) and Data(21) - an array of 21 specific worksheet cell references
I then select C1 and with active.formula insert the consistent path, File and Data(1).
Then C2 with path name, File and Data(2). Then C3 path name, File and Data(3). & So on for the 21 variables in the array - not elegant but it works okay
I am now at the point where I need to move down the rows and repeat this for each source.
I am wondering (hoping ) there is a simple way of offsetting this for the 100 rows / source files. I would also like to be able to set the offset repeat by counting the number of populated rows in Col A.
The code (from memory so syntax may be a bit wonkey):
How would I loop this macro to drop down one row to B4, run through the procedure (there are always the same number of rows to move), and continue to offset one row until reaching the end of the data?
The problem is that when I pull report data into excel, the data and headings end up in the first three columns. This is a simple cut, paste and delete macro that I recorded. I need it to offset to b4 after moving the data under b2, run, then b5, run, ect. so at the end I will have a list of numbers in column B and the coresponding data on the same row.
I would like click in cell a6 and then click a button loaded with VBA code that would:
1. Offset over 2 and down 1 to c7 so that is the current cell 2. Repeat down until an empty cell is reached (our example will be c10) 3. Put the items found in c7, c8, c9 into a variable (is that right?)
Variable would then be used in a vba generated email that I have all ready to go. I would want each item placed in the email one after the other like:
My code (with help from this forum) loops through all workbooks, all sheets and all columns OK as I have tested it with message boxes
I need to take the value of Range("C5") from each column of all sheets of all workbooks and paste it to Range("A4") downwards in Workbook("Loop Folder.xls") . That is, each new value is inserted in the next row of column A.
Sub test4() ' populate analysis sheet ' copies cell("C5") from each column in each sheet in each workbook in a directory
Dim Mypath As Variant Dim excelfile As Variant
Mypath = "U:September 2006" ' folder where all excel files reside excelfile = Dir(Mypath & "*.xls")
I have a data sheet with employee information. Only one column. It prefixes information with codes, but keeps it in the same cell. I want to move data of certain types into their own columns, but the amount of data is variable, so I cannot simply move every Nth cell, etc.
So you see some employees may have different codes altogether. But I know that I want all the cells that start with 200 to be offset (-1,1), and all the cells that start with 204 to be offset (-1,2), and so on so that basically I end up with columns of info instead of a one column list.
I have been reading and studying other peoples' macros, and am just starting to grasp the basic. When I wrote my own to accomplish this, I put this together, which doesn't work. But I don't know enough to know what I don't know.
I have this code attached to a button on the first sheet of a workbook with hundreds of sheets.
it is suposed to look for a cell that contains "SAY:" and then move one column to the right and make it a zero. It works on the first sheet but not on any other sheet.
I'm trying to use an offset loop to write form data onto a closed workbook. It works fine when the sheet is blank but as soon as I fil the first row it sticks when running. I'm not getting any error in the code and am at a bit of a loss.
Here's what I'm using:
Do If IsEmpty(ActiveCel) = False Then ActiveCell.Offset(1, 0).Select End If Loop Until IsEmpty(ActiveCell) = True ActiveCell.Value = txtName.Value
I am having some difficulties using a combination of IF and the OFFSET function to display a range of cell values from another column based on a simple condition. The values I need to display at the destination cells should be offset by 8 columns to the right and "X" rows down from the reference column. The value "X" is to be determined via the IF function to check for the row index number.
For example, if Index value "X" = 8, then display the value of B2 in cell I9. IF X = "9", display B2 in cell I10 etc.
I have attached a sample worksheet that provides some examples.
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!
(1) the user inputs a number into cells B2:B6 (arbitrarily shown as 3,4,3 and 2)
(2) the user then inputs a series of values into the respective columns E, G, I or K (corresponding to examples A-D, respectively) with SPACING between each value corresponding to the value entered in B2:B6.
For example, the value "4" is chosen in B3, so values are entered in column G at time = 0,4,8,12,16,20....etc
As another example, the value "3" is chosen in B4, so values are entered into column I at time = 8,11,14,17,20,23...etc, ie. the starting point is not necessarily t = 0.
(3) once the values have been entered as described in point (2) above, a series of results are automatically calculated in columns F,H,J and L.
NOTE: I have omitted the formulae for the calculation and have just entered arbitrary (color coded for clarity only-i don't need color coding!) numbers alongside each inputted value for the 4 examples A-D.
OK, so what I want to extract from the table for each example is the paired time AND result values, and then show them in a new table.
I have used an OFFSET formula (originally suggested by "daddylonglegs") to do this, and the results i GET are shown in columns O-V.
HOWEVER, what i WANT is the output as shown in columns Y-AF.
So as you will notice, there are 2 problems:
(1) Example C in columns S/T: value in cell B4 = 3, but the first value entered in column I does not start at a multiple of 3, so no values are returned in columns S/T because the offset function only uses row 6 as a reference point. What i want is the result shown in columns AC/AD.
How do i write a formula which says, "look down a column, find the first cell that has a value in it, and then offset from that cell/row" ?
(2) Example D in columns U/V: since the first input in column K starts a t = 12 (ie, cell K18), then i have 5 rows of empty space in columns U/V. What i want is the result shown in columns AE/AF.
Lastly, i should add that i am not necessarily stuck on using OFFSET function, since i keep reading that it is quite volatile.
I am trying to work out how to nest offset in a code using search replace. The goal is to find a value from cell A1 (example) and replace the values in the cells next to the cell containing samuel and the cell containing samuel.
A sort of search and remove data tool if you like So for example:
[QUOTE]A1: "samuel" (the search criteria) Search range is: B1:D400 (for example) Cell B40 = samuel C40 = Driver D40 = year
So, the macro is activated and finds "samuel" in B40 and I would like C40 & D40 replaced with "" The code I'm using is below: (this is just replacing the cell containing the search criteria with "test". I would like to nest offset(0,2) & offset(0,3).Value = ""
Sub Macro1() Range("B1:D400").Select Selection.Replace What:=Sheets("Sheet1").Range("A1").Value, Replacement:="test", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False End Sub
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
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
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
Going through a loop, I am trying to load pictures into an image box (or alternatively into a label) one by one i.e. going through the loop the first time, I want to load picture 1, then on the second loop, picture 2 and so on. A bit like an automated slide show.
I have written a simple loop and have used the loadpicture function to load the picture into the image box. When the code runs, the image box only gets populated after the last run through the loop. I have tried using application.screen updating function and the image.activate function without success. It is a simple bit of code and I expect an easy problem to solve if you know excel vba well.