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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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
Indeed, this way it's working. Still I don't understand why it doesn't work the other way...

In my tests the 2 ways worked.
Well, the important thing is that you already have an option working for you.
 
Upvote 0

Forum statistics

Threads
1,213,528
Messages
6,114,154
Members
448,553
Latest member
slaytonpa

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