J
John
Hi everyone
I haven't got very much experience with Excel programming and I am
stuck. I need to generate a spread sheet on the fly and dynamically
insert number of functions at various locations using Visual Basic
(locations depend on how many questions and responses are required by
user). When I tried to use the following method:
************************************************************
ActiveCell.FormulaR1C1 = "=COUNTIF(RC[-48]:RC[-1], 1)"
************************************************************
it worked fine
When I manually tried to use the counter as in:
************************************************************
Dim i as integer
i = 48
ActiveCell.FormulaR1C1 = "=COUNTIF(RC[-" & i & "]:RC[-1],1)"
************************************************************
it worked fine for each cell as a manually moved from cell to cell and
ran the procedure
However, as soon as tried to write a dynamic procedure as
************************************************************
Dim i as integer
For i = 2 To intNoRows 'Generate Functions
Application.ActiveSheet.Cells(intRows, intNoColumns +
2).FormulaR1C1 = "=COUNTIF(RC[-" & i & "]:RC[-1],1)"
Next i
************************************************************
OR
************************************************************
For i = 2 To intNoRows 'Generate Functions
Application.ActiveSheet.Cells(intRows, intNoColumns + 2) =
"=COUNTIF(RC[-" & i & "]:RC[-1],1)"
Next i 'I got rid of .FormulaR1C1 in this sample
************************************************************
the application generates
"Run time error ‘1004'
Application-defined or object-defined error"
I don't know what the error is or how to correct it.
Any help will be appreciated.
I haven't got very much experience with Excel programming and I am
stuck. I need to generate a spread sheet on the fly and dynamically
insert number of functions at various locations using Visual Basic
(locations depend on how many questions and responses are required by
user). When I tried to use the following method:
************************************************************
ActiveCell.FormulaR1C1 = "=COUNTIF(RC[-48]:RC[-1], 1)"
************************************************************
it worked fine
When I manually tried to use the counter as in:
************************************************************
Dim i as integer
i = 48
ActiveCell.FormulaR1C1 = "=COUNTIF(RC[-" & i & "]:RC[-1],1)"
************************************************************
it worked fine for each cell as a manually moved from cell to cell and
ran the procedure
However, as soon as tried to write a dynamic procedure as
************************************************************
Dim i as integer
For i = 2 To intNoRows 'Generate Functions
Application.ActiveSheet.Cells(intRows, intNoColumns +
2).FormulaR1C1 = "=COUNTIF(RC[-" & i & "]:RC[-1],1)"
Next i
************************************************************
OR
************************************************************
For i = 2 To intNoRows 'Generate Functions
Application.ActiveSheet.Cells(intRows, intNoColumns + 2) =
"=COUNTIF(RC[-" & i & "]:RC[-1],1)"
Next i 'I got rid of .FormulaR1C1 in this sample
************************************************************
the application generates
"Run time error ‘1004'
Application-defined or object-defined error"
I don't know what the error is or how to correct it.
Any help will be appreciated.