Copy a formula to a range of cells via VB6 using .Range(Cells(row,col), Cells(row,col)).Formula= statement
Tom,
Still get the error. While debugging, when I hover the mouse over Cells
the message is the following:
Cells(3, 58) = <Method 'Cells of object '_Global' failed
I run the following code with now error so I believe 'Transformed data'
sheet is active...
Seems like this would be so straight forward......
Thank you!
Kevin
' Clear Parameters: Citizenship Section
Set oSheet = oBook.Worksheets("Transformed data")
oSheet.Range("BG2:CE2").Value = ""
oSheet.Range("BH3:CE3").Value = ""
oSheet.Range("BG4:CE320").Value = ""
'Transfer the array to the worksheet
oSheet.Range("BG2:CE2").Resize(1, iCitizenshipCount).Value =
aCitizenshipTransformedData
With oBook.Worksheets("Transformed data").Range( _
Cells(3, 58), Cells(320, 58 + iCitizenshipCount)).Formula = _
Range("BG3").Formula
End With
"Tom Ogilvy" wrote in message
...
With oBook.Worksheets("Transformed data").Range( _
.Cells(3, 58), .Cells(320, 58 + iCitizenshipCount)).Formula = _
.Range("BG3").Formula
end With
If "Transformed data' is not the activesheet, then you would need to use a
construct like the above. In any event, there is no reason the above
would
not work. (unless 58 + iCitizenshipCount 256) or the formula in BG3
goes
bad when converted for the cells you are working with.
--
Regards,
Tom Ogilvy
"Kevin" wrote in message
...
I need to copy a single formula cell to a range of cells. I can do it
with
a range statement I learned of yesterday but I want to use cell notation
so
I can make the cell copy dynamic. How can I do it? For reference, the
formula in my cell to copy from looks like this:
=IF(SectionData!$I3='Transformed data'!BG$2,1,0).
Thanks in advance!
Kevin
This works great but I'd like to use cell notation instead.
' Copies a single formula cell to a range of cells.
oBook.Worksheets("Transformed data").Range("BG4",
"CE321").Formula
=
_
oBook.Worksheets("Transformed data").Range("BG3").Formula
In this experiment I get the error "Object variable or With Block
variables
not set". I haven't figured how to solve the error message but this is
the
formula I really need to make work
oBook.Worksheets("Transformed data").Range(Cells(3, 58),
Cells(320,
58 + iCitizenshipCount)).Formula = _
oBook.Worksheets("Transformed data").Range("BG3").Formula
In this experiment the cells copied but it copied the exact formula to
each
cell, the formula cell references did not change. Also, this is very
slow!
For X = 3 To 320
For Y = 1 To iCitizenshipCount
oSheet.Cells(X, 58 + Y).Formula =
oBook.Worksheets("Transformed data").Range("BG3").Formula
Next
Next
Here is how I clear and copy data to the spreadsheet with no problems:
' Clear Parameters: Citizenship Section
Set oSheet = oBook.Worksheets("Transformed data")
oSheet.Range("BG2:CE2").Value = ""
oSheet.Range("BH3:CE3").Value = ""
oSheet.Range("BG4:CE320").Value = ""
'Transfer the array to the worksheet
oSheet.Range("BG2:CE2").Resize(1, iCitizenshipCount).Value =
aCitizenshipTransformedData
|