Cell References in VBA

Tills13

New Member
Joined
Jun 6, 2011
Messages
15
Good Afternoon,

I'm writing a little program for my school and I've run into a small problem.

The code in question is:
Code:
Range(Cells(19, 1), Cells(19, 3)).Copy
Range(Cells(19 + Count, 1), Cells(19 + Count, 3)).PasteSpecial (xlPasteFormats)
Cells(19 + Count, 1).Value = Cells(18 + Count, 1).Value + 1
Cells(19 + Count, 2).Value = CompleteString
Cells(19 + Count, 3).Formula = "(this is where I'm stuck)"

Where I've written "this is where I'm stuck" I'd like to have a reference to another cell, it will just duplicate the value in that cell by referencing it. However, I cannot figure out how to do that.

I don't think I'm being clear enough, so I'll give you an example. Other code in my project adds a pre-formatted area where a user would input a number of values and it would sum them in a "totals" cell underneath the area. The cell I am stuck on will replicate this value in another part of the sheet.

I've tried, foolishly, I discovered,
Code:
Cells(19 + Count, 3).Formula = "=Cells(15 + (Count * 8), 11)"
but that obviously didn't work. (15 + (Count * 8), 11) is the location of the cell that I want to reference at all times. As I add areas, count increases.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi there, and welcome to Mr Excel!

I'd love to help, and I understand your code (well, most of it) but there are a couple of points:

1. Am I right in my thinking that you've used what appears to be your own variable called "Count"? Have you set this variable anywhere in your code, and what does it reference? The reason I'm asking is that we could do with understanding this, to be sure about the workings of the code, and the syntax.
2. The other reason for asking is that Excel has it's own built-in function called "Count" and using this name for your own variable (if you have) could cause a conflict.

It may help us if you post the whole procedure, so we can see how it all works together.
 
Upvote 0
If you use R1C1 notation, it's a fairly simple substitution:
Code:
Cells(19 + Count, 3).FormulaR1C1 = "=R"& 15 + (Count * 8) & "C11"
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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