https://app.box.com/s/r8zvw43s3aku8i30vp8plftgxro3fnrr" onclick="window.open(this.href);return false;Doc.AElstein wrote:Hi
I think you have given one wrong link -
You have given the same link for both files.
Alan
My bad try this one.
https://app.box.com/s/r8zvw43s3aku8i30vp8plftgxro3fnrr" onclick="window.open(this.href);return false;Doc.AElstein wrote:Hi
I think you have given one wrong link -
You have given the same link for both files.
Alan
Code: Select all
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Code: Select all
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
Code: Select all
Sub CopyCellsFormulas()
Dim dteDateValue As Date
Dim I As Integer, J As Integer, intStartRow As Integer, R As Integer
Dim dbl9Value As Double, dbl21Value As Double
Const defName As String = "DataCol"
Const defNameOEX_High As String = "OEX_High"
Const defNameOEX_Low As String = "OEX_Low"
Const defNameDATE_Range As String = "DATE_Range"
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
'New Data Aquisitions Begins 10/21/2003 Put/Call
'01/02/2004 Row 53
'07/01/2004 Row 177
'01/03/2005 Row 305
'07/01/2005 Row 430
'01/03/2006 Row 557
'07/03/2006 Row 682
'01/02/2009 Row 1312
'01/03/2012 Row 2067
'07/02/2012 Row 2142
'01/02/2013 Row 2267
'07/01/2013 Row 2391
'01/02/2014 Row 2519
'07/01/2015 Row 3148
'07/01/2016 Row 3199
'intStartRow = 3199
'I = intStartRow
Dim ws As Worksheet: Set ws = Worksheets("Vix")
Worksheets("Vix").Activate
Dim Lr As Long: Let Lr = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
Dim Sr As Long: Let Sr = (ws.Cells(ws.Rows.Count, "F").End(xlUp).Row) + 1
'Do
'I = I + 1
'Range(Cells(I - 2, 6), Cells(I - 2, 9)).Copy Range(Cells(I - 1, 6), Cells(I - 1, 9))
'Loop Until Cells(I, 2) = ""
Rem Code section to help get Formulas: Put stop in left margin at Set rngVix = .. then run code and Hit Ctrl+G to display Immediate Window
Dim Temp() As Variant: Let Temp() = Worksheets("Vix").Range("F" & (Sr - 1) & ":I" & (Sr - 1) & "").Formula
Debug.Print Temp(1, 1) ' =(F3258*$I$3)+(E3259*$I$2)
Debug.Print Temp(1, 2) ' =G3258*$I$7+E3259*$I$6
Debug.Print Temp(1, 3) ' =F3259/G3259
Debug.Print Temp(1, 4) ' =AVERAGE(E3210:E3259)
Dim rngVix As Range ' variable to hold the entire Range you are currently considering to add formulers to
Set rngVix = Worksheets("Vix").Range("F" & Sr & ":I" & Lr & "")
Dim arrrngVix() As Variant ' We know the size of the Array, but must use Re Dim below as Dim only takes Numbers. We must use Variant as otherwise the final Paste Out to the Worksheet for Formula strings does not always work. http://www.mrexcel.com/forum/excel-questions/887822-formula-link-cell-array-instead-cell-value-based-cell-r-c-co-ordinates-2.html
ReDim arrrngVix(1 To rngVix.Rows.Count, 1 To 4) ' We must use Redim as this allows us to use the Rows Count Property
Dim Cntrw As Long
For Cntrw = 1 To (UBound(arrrngVix(), 1) - 0) ' at every "row" in the Array, (Up to and including the last), we ...
' ... Put in each string Formula
Let arrrngVix(Cntrw, 1) = "=(F" & Sr - 2 + Cntrw & "*$I$3)+(E" & Sr - 1 + Cntrw & "*$I$2)" '
Let arrrngVix(Cntrw, 2) = "=G" & Sr - 2 + Cntrw & "*$I$7+E" & Sr - 1 + Cntrw & "*$I$6" '
Let arrrngVix(Cntrw, 3) = "=F" & Sr - 1 + Cntrw & "/G" & Sr - 1 + Cntrw & "" '
Let arrrngVix(Cntrw, 4) = "=AVERAGE(E" & Sr - 50 + Cntrw & ":E" & Sr - 1 + Cntrw & ")" '
Next Cntrw
Let rngVix.Value = arrrngVix() ' This will paste out the Formula values to the Worksheet
If this is correct then it is what I am seekingDoc.AElstein wrote: At this point the Before and After for Worksheets “Vix” are identical
Code snippet for last post
Code: Select all
Sub CopyCellsFormulas() Dim dteDateValue As Date Dim I As Integer, J As Integer, intStartRow As Integer, R As Integer Dim dbl9Value As Double, dbl21Value As Double Const defName As String = "DataCol" Const defNameOEX_High As String = "OEX_High" Const defNameOEX_Low As String = "OEX_Low" Const defNameDATE_Range As String = "DATE_Range" Application.EnableEvents = True Application.ScreenUpdating = True Application.Calculation = xlAutomatic 'New Data Aquisitions Begins 10/21/2003 Put/Call '01/02/2004 Row 53 '07/01/2004 Row 177 '01/03/2005 Row 305 '07/01/2005 Row 430 '01/03/2006 Row 557 '07/03/2006 Row 682 '01/02/2009 Row 1312 '01/03/2012 Row 2067 '07/02/2012 Row 2142 '01/02/2013 Row 2267 '07/01/2013 Row 2391 '01/02/2014 Row 2519 '07/01/2015 Row 3148 '07/01/2016 Row 3199 'intStartRow = 3199 'I = intStartRow Dim ws As Worksheet: Set ws = Worksheets("Vix") Worksheets("Vix").Activate Dim Lr As Long: Let Lr = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row Dim Sr As Long: Let Sr = (ws.Cells(ws.Rows.Count, "F").End(xlUp).Row) + 1 'Do 'I = I + 1 'Range(Cells(I - 2, 6), Cells(I - 2, 9)).Copy Range(Cells(I - 1, 6), Cells(I - 1, 9)) 'Loop Until Cells(I, 2) = "" Rem Code section to help get Formulas: Put stop in left margin at Set rngVix = .. then run code and Hit Ctrl+G to display Immediate Window Dim Temp() As Variant: Let Temp() = Worksheets("Vix").Range("F" & (Sr - 1) & ":I" & (Sr - 1) & "").Formula Debug.Print Temp(1, 1) ' =(F3258*$I$3)+(E3259*$I$2) Debug.Print Temp(1, 2) ' =G3258*$I$7+E3259*$I$6 Debug.Print Temp(1, 3) ' =F3259/G3259 Debug.Print Temp(1, 4) ' =AVERAGE(E3210:E3259) Dim rngVix As Range ' variable to hold the entire Range you are currently considering to add formulers to Set rngVix = Worksheets("Vix").Range("F" & Sr & ":I" & Lr & "") Dim arrrngVix() As Variant ' We know the size of the Array, but must use Re Dim below as Dim only takes Numbers. We must use Variant as otherwise the final Paste Out to the Worksheet for Formula strings does not always work. http://www.mrexcel.com/forum/excel-questions/887822-formula-link-cell-array-instead-cell-value-based-cell-r-c-co-ordinates-2.html ReDim arrrngVix(1 To rngVix.Rows.Count, 1 To 4) ' We must use Redim as this allows us to use the Rows Count Property Dim Cntrw As Long For Cntrw = 1 To (UBound(arrrngVix(), 1) - 0) ' at every "row" in the Array, (Up to and including the last), we ... ' ... Put in each string Formula Let arrrngVix(Cntrw, 1) = "=(F" & Sr - 2 + Cntrw & "*$I$3)+(E" & Sr - 1 + Cntrw & "*$I$2)" ' Let arrrngVix(Cntrw, 2) = "=G" & Sr - 2 + Cntrw & "*$I$7+E" & Sr - 1 + Cntrw & "*$I$6" ' Let arrrngVix(Cntrw, 3) = "=F" & Sr - 1 + Cntrw & "/G" & Sr - 1 + Cntrw & "" ' Let arrrngVix(Cntrw, 4) = "=AVERAGE(E" & Sr - 50 + Cntrw & ":E" & Sr - 1 + Cntrw & ")" ' Next Cntrw Let rngVix.Value = arrrngVix() ' This will paste out the Formula values to the Worksheet
Alan
Code: Select all
Let arrrngVix(Cntrw, 1) = "=(F" & Sr - 2 + Cntrw & "*$I$3)+(E" & Sr - 1 + Cntrw & "*$I$2)" '
Let arrrngVix(Cntrw, 2) = "=G" & Sr - 2 + Cntrw & "*$I$7+E" & Sr - 1 + Cntrw & "*$I$6" '
Let arrrngVix(Cntrw, 3) = "=F" & Sr - 1 + Cntrw & "/G" & Sr - 1 + Cntrw & "" '
Let arrrngVix(Cntrw, 4) = "=AVERAGE(E" & Sr - 50 + Cntrw & ":E" & Sr - 1 + Cntrw & ")" '
It appears to me to give identical results. Yesterday I tested it over a larger range and it gave what appeared to be the correct results – it gave the same results yesterday as your code , ( but without crashing ), in the First File you uploaded.bknight wrote:If this is correct then it is what I am seekingDoc.AElstein wrote: At this point the Before and After for Worksheets “Vix” are identical
I did not give it a lot of thought. – I just copied the formula that is therebknight wrote:...Without a great amount of analyzing, why the parenthesis in the first statement and not in the other three...
Probably. ( I just took a look at the other Worksheets and the Before and After Files appear to be the same for those other worksheets.? )bknight wrote:....
The code needs to be duplicated, ..... Then the affected columns in the rest of the sheets will need to be altered.
Cntrw is the Loop Bound variable count, it takes on the value 1, 2, 3, 4 etc.. up to the maximum rows to have formulas put in them . You can use the same variable, Cntrw . in all Loopsbknight wrote:.....
The code needs to be duplicated, with different Cntrw, (Cntrw1, Cntrw2, Cntrw3). .....
When coding the initial steps the other night, I got a Duplicate declaration error, until I changed them as I posted. Look at code in either file I uploaded.Cntrw is the Loop Bound variable count, it takes on the value 1, 2, 3, 4 etc.. up to the maximum rows to have formulas put in them . You can use the same variable, Cntrw . in all Loops
It is just personal preference. Most people would use the same variable , Cntrw for all loops.
If it were my code, I would do it untypically. I would have a Cntrw for each Worksheet, like CntrwVix, CntrwPCRat etc. - But that is an untypical personal preference. It declares extra variables unnecessary.
You can re Set = ( and re Let =) a variable as much and as often as you like.bknight wrote:When coding the initial steps the other night, I got a Duplicate declaration error, until I changed them as I posted. ....Cntrw is the Loop Bound variable count, it takes on the value 1, 2, 3, 4 etc.. up to the maximum rows to have formulas put in them . You can use the same variable, Cntrw . in all Loops......
Code: Select all
Sub CopyCellsFormulasTest()
Dim dteDateValue As Date
Dim I As Integer, J As Integer, intStartRow As Integer, R As Integer
Dim Lr As Long, Sr As Long, Cntrw As Long
Dim dbl9Value As Double, dbl21Value As Double
Dim Temp() As Variant
Dim rngWs As Range ' variable to hold the entire Range you are currently considering to add formulers to
Dim arrrngWs() As Variant ' We know the size of the Array, but must use Re Dim below as Dim only takes Numbers. We must use Variant as otherwise the final Paste Out to the Worksheet for Formula strings does not always work.
'http://www.mrexcel.com/forum/excel-questions/887822-formula-link-cell-array-instead-cell-value-based-cell-r-c-co-ordinates-2.html
Dim ws As Worksheet
Const defName As String = "DataCol"
Const defNameOEX_High As String = "OEX_High"
Const defNameOEX_Low As String = "OEX_Low"
Const defNameDATE_Range As String = "DATE_Range"
.....
Let Temp() = Worksheets("Vix").Range("F" & (Sr - 1) & ":I" & (Sr - 1) & "").Formula
....
Let Temp() = Worksheets("PutCall Ratio").Range("F" & (Sr - 1) & ":H" & (Sr - 1) & "").Formula
....
Let Temp() = Worksheets("OEX").Range("H" & (Sr - 1) & ":H" & (Sr - 1)& "").Formula
...
End Sub
Code: Select all
Debug.Print Temp(1, 1) ' =(F3312*$I$3)+(E3313*$I$2)Lr=3315 Sr=3314
Set rngWs = Worksheets("OEX").Range("H" & Sr & ":H" & Lr & "")
ReDim arrrngWs(1 To rngWs.Rows.Count, 1 To 4) ' We must use Redim as this allows us to use the Rows Count Property
For Cntrw = 1 To (UBound(arrrngWs(), 1) - 0) ' at every "row" in the Array, (Up to and including the last), we ...
...
Code: Select all
Set ws = Worksheets("PutCall Ratio")
Worksheets("PutCall Ratio").Activate
Let Lr = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
Let Sr = (ws.Cells(ws.Rows.Count, "F").End(xlUp).Row) + 1
'Do
'I = I + 1
'Range(Cells(I - 2, 6), Cells(I - 2, 9)).Copy Range(Cells(I - 1, 6), Cells(I - 1, 9))
'Loop Until Cells(I, 2) = ""
Rem Code section to help get Formulas: Put stop in left margin at Set rngVix = .. then run code and Hit Ctrl+G to display Immediate Window
Let Temp() = Worksheets("PutCall Ratio").Range("F" & (Sr - 1) & ":H" & (Sr - 1) & "").Formula
Debug.Print Temp(1, 1) ' =(F3312*$I$3)+(E3313*$I$2)Lr=3315 Sr=3314
Debug.Print Temp(1, 2) ' =SUM(E3233:E3313)/81
Debug.Print Temp(1, 3) ' =F3313/G3313
Set rngWs = Worksheets("PutCall Ratio").Range("F" & Sr & ":H" & Lr & "")
ReDim arrrngWs(1 To rngWs.Rows.Count, 1 To 4) ' We must use Redim as this allows us to use the Rows Count Property
For Cntrw = 1 To (UBound(arrrngWs(), 1) - 0) ' at every "row" in the Array, (Up to and including the last), we ...
' ... Put in each string Formula
Let arrrngWs(Cntrw, 1) = "=(F" & Sr - 2 + Cntrw & "*$I$3)+(E" & Sr - 1 + Cntrw & "*$I$2)" '
Let arrrngWs(Cntrw, 2) = "=SUM(E" & Sr - 81 + Cntrw & ":E" & Sr - 1 + Cntrw & ")/81" '
Let arrrngWs(Cntrw, 3) = "=F" & Sr - 1 + Cntrw & "/G" & Sr - 1 + Cntrw & "" '
Next Cntrw
Let rngWs.Value = arrrngWs() ' This will paste out the Formula values to the Worksheet
That would be the next step, I didn't post it, because I'm still in the process of coding.HansV wrote:1) Change all occurrences of Temp() to Temp
2) After the 3rd Let Temp = ..., refer to Temp instead of to Temp(1, 1).
Never got that far, but understood.HansV wrote:Did you change Temp() to Temp in the declaration (Dim Temp() As Variant)?
After the line
Let Temp = Worksheets("OEX").Range("H" & (Sr - 1) & ":H" & (Sr - 1)& "").Formula
you should refer to Temp, not to Temp(1, 1) or similar.
This does not work either, gives runtime error 438 Object doesn't support this property or method.Doc.AElstein wrote: ...
_...................
If the Range is a single Cell , then as Hans said you will not get a Field , but a single value is returned.
Equating an Array to a single value will give you the mismatch type error you observed
_............
Worksheets("OEX").Range("H" & (Sr - 1) & ":H" & (Sr - 1)& "").Formula
The code needs to get to that statement firstly.
Is the same as
Worksheets("OEX").Range("H" & (Sr - 1) & “”).Formula
That is similar to a line like
Worksheets("OEX").Range("H2”).Formula
And
Worksheets("OEX").Range("H2:H2”).Formula
The above will return a string of a formula, ( assuming the cell has a Formula in it )
The appropriate variable type to “take” that would be, for example a String, like
Dim strtemp As String
Let strTemp = Worksheets("OEX").Range("H" & (Sr - 1) & “”).Formula
then you do_...
Debug.Print strTemp
_....in order to see that single formula string in the immediate window