VBA copy formula instead of value

Strooprover

New Member
Joined
Jul 21, 2017
Messages
25
Hi,

I've got this code to copy the formula in F1 below for the amount of values in G1. But I think that in my last line I somehow give the order to copy the value of F1, instead of the formula of F1. At least, that's that happens in my worksheet. Can someone explain to me what I'm doing wrong?

Code:
  Range("F1").Select
        ActiveCell.FormulaR1C1 = "=COUNTIF(Sheet1!C[-5],Sheet2!RC[+2])"
lastrow = Worksheets("Sheet2").Range("H1").End(xlDown).Row
With Worksheets("Sheet2").Range("F1")
.AutoFill Destination:=Range("F1:F" & lastrow)
End With
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi

Your code appears to put formulas when I tried it. You could simplify it though...

Code:
lastrow = Worksheets("Sheet2").Range("H1").End(xlDown).Row


Worksheets("Sheet2").Range("F1:F" & lastrow).FormulaR1C1 = "=COUNTIF(Sheet1!C[-5],Sheet2!RC[+2])"
 
Upvote 0
Thanks for your help!

Can I ask you another question?

"I keep getting the Object variable or With block variable not set" error in the red line. Is it because I compare a string variable with a regular variable?

Thanks in advance!

Code:
Dim tabel As Stringtabel = Range("A1").Value


[COLOR=#ff0000]If ws2.Cells(x, 1) = tabel Then[/COLOR]
ws2.Cells(x, 1).Select
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top