vba code doesn't work; same code works as a macro

Mart van Hulten

New Member
Joined
Oct 9, 2018
Messages
11
<code>
Sheets(studentBlad).Select
ActiveSheet.Cells(3, kolom).Select
ActiveCell.FormulaR1C1 = "='" + naamSp + "'!RC[1]"
ActiveSheet.Cells(3, kolom).Select
Range(Cells(3, kolom), Cells(10, kolom)).FillDown
</code>
The above does what it's supposed to do when I use this in a macro, but as part of seperate vba-code, it doesnt do anything. Don't understand why.
studentBlad is a string, containing the name of a worksheet. So is naamSp
kolom is an integer (value = 77)
I am trying to copy a formula from 'naamSp'! to studentBlad
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You can put your complete code here.
What do you have in the variable naamSp?


Do you want to copy the formula or take the value?
 
Upvote 0
I want to copy the formula.
In the menatime I changed the code in VBA as follows:
<code>
Sheets(studentBlad).Select
For i = 3 To (2 + aantalStudenten)
ActiveSheet.Cells(i, kolom).Select
ActiveCell.FormulaR1C1 = "='" + naamSp + "'!RC[1]"
Next i
</code>
And it does what it's supposed to do...
 
Upvote 0
I want to copy the formula.
In the menatime I changed the code in VBA as follows:
<code>
Sheets(studentBlad).Select
For i = 3 To (2 + aantalStudenten)
ActiveSheet.Cells(i, kolom).Select
ActiveCell.FormulaR1C1 = "='" + naamSp + "'!RC[1]"
Next i
</code>
And it does what it's supposed to do...

So it works already?
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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