Hello, I am trying to insert formulas into cells with VBA by using the following formula:
The range I want the formula to be inserted into are only the rows in which there is a value present in Column B. These values are in format QF1, QF2, QF3....
So sometimes there will be 10 rows and sometimes there will be 100. So Lets say there are QF values in rows 10 to 80, so I want the script to insert different formulas (=2+2 used as example) in column D,E,F,G, but only within that range.
I've been trying to use something like the script below to find and save that range, and then the command above to insert it in the column nearby :
This script is however not working and the formulas are not inserted into cells. I think the startcell and endcell values are not saved properly. Is someone able to help?
Kind Regards
Emil
Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Range(Range(startcell), Range(endcell)).Offset(0, 1).FormulaR1C1 = "=2+2"</code>
The range I want the formula to be inserted into are only the rows in which there is a value present in Column B. These values are in format QF1, QF2, QF3....
So sometimes there will be 10 rows and sometimes there will be 100. So Lets say there are QF values in rows 10 to 80, so I want the script to insert different formulas (=2+2 used as example) in column D,E,F,G, but only within that range.
I've been trying to use something like the script below to find and save that range, and then the command above to insert it in the column nearby :
Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Dim startcell As Range
Dim endcell As Range
Range0 = "B1:B90"
Dim rng1 As Range, cell1 As Range
Set rng1 = Range(Range0)
For Each cell1 In rng1
If InStr(1, cell1, "QF") > 0 And started = False Then
Set startcell = cell1
started = True
End If
If InStr(1, cell1, "QF") > 0 And started = True Then
Set endcell = cell1
End If
Next cell1
Range(Range(startcell), Range(endcell)).Offset(0, 1).FormulaR1C1 = "=2+2"
</code>
This script is however not working and the formulas are not inserted into cells. I think the startcell and endcell values are not saved properly. Is someone able to help?
Kind Regards
Emil