Can't Get Formula To Work When Put Inside A Loop
Apr 14, 2014
LastRow = Worksheets("Sheet1").Cells(Rows.Count, "K").End(xlUp).Row
For i = 2 To LastRow
Worksheets("Sheet1").Formula = "=IFERROR(+IF(+K2=0,0,+R2/(+IF(+K2>L2,K2,L2)*$AE$1/365)/P2),0)"
If (Worksheets("Sheet1").Range("AE" & i).Value < 1.5) And _
((Worksheets("Sheet1").Range("K" & i).Value > 0) Or (Worksheets("Sheet1").Range("L" & i).Value > 0)) Then
Worksheets("Sheet1").Range("AE" & i).Font.Color = 255
End If
Next i
My loop here works just fine, and my Formula works in testing. However when I move my formula inside the loop I get an error.
Is the syntax wrong in this line = Worksheets("Sheet1").Formula = "=IFERROR(+IF(+K2=0,0,+R2/(+IF(+K2>L2,K2,L2)*$AE$1/365)/P2),0)"
View 5 Replies
ADVERTISEMENT
Jun 21, 2008
i have written a code in VBA to interpolate the value of Y0 corresponding to X0 using a set of (X,Y) points. (I have written this in module1) . This function works when i call it through a Sub or another Function in VBA. but it does not work when I try to use it as a function in my excel worksheets (when I type : =interpolate(A1:A10,B1:B10,30) .... 30 is an arbitrary value). in this case I get #value! error
The function is known in within the worksheets because when I start typing its name, the Auto Name Complete feature of excel, finds this function.
I am new to VAB for excel. Please give me a hint to see my mistakes of if something is missing inside my code.
PHP
Public Function Interpolate(ByRef X() As Double, ByRef Y() As Double, ByRef X0 As Double) As Double Dim I As Integer, Slope As Double, NData As Integer NData = UBound(X) For I = 1 To UBound(X) - 1 If (X(I) = X0) Then Interpolate = Y(I) Exit Function ElseIf (X0 < ListMax(X(I), X(I + 1)) And X0 > ListMin(X(I), X(I + 1))) Then Slope = (Y(I) - Y(I + 1)) / (X(I) - X(I + 1)) Interpolate = Y(I + 1) + Slope * (X0 - X(I + 1)) Exit Function End If Next I End FunctionPublic Function ListMax(ParamArray ListItems() As Variant) Dim I As Integer ListMax = ListItems(0) For I = 0 To UBound(ListItems()) If ListItems(I) > ListMax Then ListMax = ListItems(I) Next IEnd FunctionPublic Function ListMin(ParamArray ListItems() As Variant) Dim I As Integer ListMin = ListItems(0) For I = 0 To UBound(ListItems()) If ListItems(I) < ListMin Then ListMin = ListItems(I) Next IEnd Function
View 10 Replies
View Related
Feb 17, 2014
I am trying to create a For Loop where the RND from array column sptemp(i,2) is static throughout the entire loop when I pull the data out separately by columns to create a chart. The data works perfectly if I print it out on the excel spreadsheet via ctrl+shift+enter as an entire array but I am trying to graph the columns and the RND is updating and not syncing with the same random number, as sptemp(i,3) and sptemp(i,5) are both linked to sptemp(i,2) which is the RND. I am trying to graph column 3-5 on the Y-axis and column 1 on the X-axis, and column 3 and 5 should look identical after subtracting column 4.
View 1 Replies
View Related
Apr 17, 2009
I want to use the function VLOOKUP at my VBA program inside a FOR Loop
View 3 Replies
View Related
Oct 6, 2011
I have this loop, I get a range of specific cells and then I loop over this collection searching for a value, if this value exist I wanted to move one place to the right and then set a value on that cell, but for some reason when I put this offser(0,1) parameter, the loop became infinite, not sure why the code is doing this:
Code:
For Each c In Worksheets("Parameters").Range("A3:AR3").Cells
adress_start = ""
adress_letter = ""
[Code].....
View 2 Replies
View Related
Dec 17, 2013
I'm working within a nested FOR loop. If you notice when I'm Assigning "ECD" I'm trying to average the cells from J (which is row 1) and column 11 to column 12. It keeps on telling me "Application-Defined or object-defined error".
Code:
Sub copytab()
Dim WSName As String
Dim NumbSheets As Integer
Dim NextRow As Integer
Dim i As Integer
[Code] .......
View 9 Replies
View Related
Oct 26, 2006
The following bit of code has worked for me but when it goes back for the next b it still finds the address as $j$13. This address does match the criteria I want but what I want the programme to do is move to the next address matching the criteria in the range...
View 4 Replies
View Related
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
Jan 11, 2009
i need to work out a formula for my spreadsheet which I use to work out cutting lists for timber frames. I need it to work out if the width of a job is for eg 2400mm i need to work out how many timber studs I need so the space between each stud is between 400mm and 500mm and this will need to work for a range of different sizes of frames. I have it written at the moment and it just devides the width by 400 and gives me a amount of studs but it would work much better if it could space them between 400 & 500.
View 4 Replies
View Related
Feb 9, 2014
I'm trying to insert two rows in a subset of worksheets in a workbook by defining a range in a worksheet and loop through the worksheets in that range, but the code will only run on the active worksheet.
[Code] ..........
How I could get this loop to work?
View 1 Replies
View Related
Feb 9, 2014
I'm trying to insert two rows in a subset of worksheets in a workbook by defining a range in a worksheet and loop through the worksheets in that range, but the code will only run on the active worksheet.
Sub StatePIPData()
Dim sheet_name As Range
For Each sheet_name In Sheets("WS").Range("A:A")
If sheet_name.Value = "" Then
[Code] .......
View 1 Replies
View Related
Jan 2, 2009
I am want to copy a formula across several work sheet and have the formula always take data from previous work sheet.
2) I am working with this formula =C12+INDIRECT((MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,256)-1)&"!"&"C12")
and it comes from this thread http://www.excelforum.com/excel-gene...orksheets.html. I have included a worksheet attachment that has explanations
View 2 Replies
View Related
Aug 21, 2014
The for loop don't work in my excel 2010 macro. Probably the problem might be the Range("Fi") construct with the variable "i"?
Dim i As Integer
For i = 4 To 10004
Cells(i, 63).Select
Cells(i, 63) = Application.VLookup(Sheets(3).Range("Fi"), Sheets(4).Range("F:AY"), 45, False)
Next i
View 3 Replies
View Related
May 13, 2014
I have attached a screencap of an example source table that I am trying to write a macro to manipulate each day. Starting conditions are that I have data in column A and B. Column A would be reference numbers that may be on one line, or more likely, on multiple lines repeating with varying counts. Column B is the weight associated with each line. I would need a macro that could loop through column A, determine if the ref number has changed, and then calculate/populate column C. Column C is the % of the total weight for the unique reference number. I have illustrated this in the table using column D. This is taking me incredible manual effort to complete right now and I do know VBA, I just don't know how to loop a variable range in this case.
View 9 Replies
View Related
Aug 9, 2006
I am having a problem with a custom funciton I am trying to create. It will exit after it is finished with the IF Then Else statement. I need it to continue onto the Do loop at the bottom that does all the work.
Function UPCECheck( num As String) As Long
Dim CheckNum As Long
Dim TempCheck As Long
Dim X As Long
Dim Holdtxt As Variant
UPCECheck = 0
CheckNum = 0
Debug.Print Len(num)
If Len(num) = 12 Then
Holdtxt = num
ElseIf Len(num) < 12 Then
Holdtxt = "000000000000" & num
Holdtxt = Val(Mid(Holdtxt, Len(holdtext) - 12, 12))
End If...................
View 6 Replies
View Related
Nov 12, 2008
=BDP("067901108 cn corp cusip","px_last")
is there a way to insert 067901108 cn corp cusip from a different cell into the formula?
067901108 cn corp cusip <---A1
067901108 us corp cusip <---A2
something like this?
=BDP("A1","px_last") which equal to =BDP("067901108 cn corp cusip","px_last")
=BDP("A2","px_last") which equal to =BDP("067901108 us corp cusip","px_last")
View 2 Replies
View Related
Jun 21, 2014
I have an excel work book that I want to extract certain info from Each tab where in the result tab I use this formula to get required data from another tab.
I has about 24 tab , in the 25th one i collect data from all previous , using below formula inside each cell to get
=INDEX('2014 wk12'!$C$1:$C$17,MATCH("Total LTD Result",'2014 wk12'!$A$1:$A$17,0))
Where 2014 wk12 is a tab name , so , it works fine
excel iss.png
What i want is t replace the sheet name which in previous example is 2014 wk12 with relative name in column A
The closest i have in mind is to make it as below ( it is not working ) so what shall be the working formula of the below
=INDEX('Tab name from Column A '!$C$1:$C$17,MATCH("Total LTD Result",'Tab name from Column A'!$A$1:$A$17,0))
View 6 Replies
View Related
Mar 8, 2007
=StacServer|Windham! '40720'
This is the format of an external call that I am trying to run. I need to change the number (40720) based on the day of the month (i.e. if its the 5th, then use 40725.
I am attemting to use a function to do this and passing in the device name (Windham) and location (40720). Unfortunately, I have been unable to get a String to send back as a formula. My attempt was as follows :
= Location ("Windham", 40720, "D7")
Function Location(name, num, cell)
Dim psDay As Integer
Dim psLocal As String
psDay = Day(Now)
Location = (Range(cell).Formula = "=StacServer|" & name & "!'" & (num + psDay) & "'")
End Function
View 9 Replies
View Related
Feb 22, 2013
I tried to count rows from one sheet and to put this value as counter in VBA For-Next loop.
VB:
Sub Copy_ID()
'
' Copy_ID Macro
[Code]...
It ends with "Invalid qualifier" error on the counter.Formula line. I attached sample excel with macro that I listed here.
View 5 Replies
View Related
Jun 21, 2014
I have a challenge with conditional formatting. I have products A-K with sales current year and last year and want to have year on year growth. I want to have one column where the cell formatting changes based on data validation.
Let's say product A sold 60 items CY and 50 LY meaning YoY variance is +10 items or +20%. Hence, if the relevant cell says "%" then the YoY figure should say "+20%" (formatted as a percentage) and if "VALUES" then YoY should be 10 (formatted as numbers/absolute values).
Remember also that YoY growth can be +100% (or more), 0% and -100%.
View 10 Replies
View Related
Dec 6, 2005
I am currently using the STDEV formula. Is there a way, that i can make
the formula use data from nonblank cells, only. For example: A1, A2, A5 will
have numbers listed. A3 & A4 are blank. Can i get the formula to use only
A1, A2, & A5?
View 9 Replies
View Related
May 22, 2013
I know about
(isnumber(match({,12054, 12056, 12058}).....
How could I express a range of numbers to identify 12054-13001. How would that expression be written?
View 5 Replies
View Related
Aug 15, 2014
For some reason Absolute $ or INDIRECT is not working inside my formula when I add a row to my chart. Formula keeps adjusting.
Here is my formula...=IFERROR(LARGE(IF($B$5:$B$50=$K108,$A$5:$A$50),1),"")
$B$5:$B$50 goes to $B$6:$B$51 AND $A$5:$A$50 goes to $A$6:$A$51..... it can't do that, throws my counts out, needs to stay in this range B5:B50 and A5:A50 when I add a row to chart
Also when I use INDIRECT
=IFERROR(INDIRECT(LARGE(IF("B5:B50"=$K108),INDIRECT("A5:A50"),1),""))))
I keep getting a error with =$K108, which is a cell reference in my formula which the formula needs to look at
So what do I do, or what formula do I need to use to stop this from adjusting as I add rows to a chart to stop formula from adjusting?
View 8 Replies
View Related
Nov 9, 2009
I'm trying to use some data from other workbooks in a formula. However, the path to the other workbooks we are using will often change.
I think that the user can enter the path to the other workbook in a cell in this workbook. However, I'm getting errors in my formula and am not sure how to make the formula use the cell to reference the location of the workbook that has the data that we want.
This is what I have, but it's giving me an error.
=Countif(' & 'Instructions'!B9 & Planning'!$I$3:$I$100, "C")
'Instructions'!B9 contains the location of the other workbook in the format \path[filename] Planning'!$I$3:$I$100 is the location of the range in the other workbook.
View 7 Replies
View Related
Jul 29, 2013
I am making a buiness card request form, which I have attached. On the Master Sheet (Sheet 1), the user enters in his/her personal data, such as his name address, phone number, etc. After he/she finished entering all the relevant data, Business Card Layout (Sheet 2) automatically populates and shows the user what their business card will look like.
Everything works fine, however I just realized that the contact information might vary from person to person. Right now, a person can enter 5 different contact information, but most of them will probably only choose four.
I wanted to know how to shift the cells down if the user does not fill out one of the contact information.
View 2 Replies
View Related
Feb 7, 2014
How do I change a Positive number into a Negative number inside a cell formula?
I have a figure in Cell AE 101 which has the positive number 141
I have another cell W1 which has the positive number of 437
I want to create a formula in cell X1 that takes the number in cell AE 101 of 141 and convert the number inside the formula of 141 into a negative number of -141 and then subtracts that number from Cell W1 of 437 leaving an equation inside the formula to read. 437-141 = 296
Since the number in Cell W1 changes all the time and the number in AE101 Changes all the time the new formulated number in X1 will change all the time too as the cells get updated.
View 6 Replies
View Related
Apr 17, 2007
This IF formula does not work on the last part of this formula
IF(E10>50,"$50.00",0)))) and I think there is a conflict with the
IF(E9>199,(E9*0.01) but I cannot figure out what the problem is.
=IF(E8>0,"$0.00",IF(E9199,(E9*0.01),IF(E10>50,"$50.00",0))))
View 9 Replies
View Related
Aug 11, 2014
I have some problem with my excel formula here. It works in some rows but doesn't in others.
I have attached the excel file herewith : Book1.xlsx
View 4 Replies
View Related
Aug 7, 2014
See the attached workbook.
Please edit the formula in column B so that it only gives a BINGO if the adjacent cell in column G is less than 51.
So cell M16 should not be a BINGO because cell G16 is not less than 51.
Attached Files : Book1.xlsx‎
View 3 Replies
View Related
Jan 8, 2014
Combing these two formulas. I have a work schedule spreadsheet. If the employee is Off I want the value to = 0 (zero hours). But if the cell has a start time I need it to calculate those hours. I know both of the formulas work individually. But I need them to work together.
Formula for when cell says OFF:
=IF(C11="Off",0)
And the second
Formula to calculate hours (based on start time/finish time is the same for all employees)
=($X$4-C11+($X$4<C11))*24
View 2 Replies
View Related