Data exchange between macro and spreadsheet

A

alfurfine

I'm using VBA in Excel 2000. In my macroI have created variables x and
y, each as
Integer. I use For .. Next to cause the spreadsheet to calculate for
each iteration a result
which appears in a designated cell of the spreadsheet.
I then wish to assign that cell value to the macro variable x. How do
I perform this Copy/Paste operation?
Further, I wish to total all such results for x into the variable y
via the macro line: y=y+x. And then I wish to display the final value
for y as a cell in the spreadsheet. How do I effect that Copy/Paste
operation?

Many thanks.

-- Allen
 
G

GS

alfurfine brought next idea :
I'm using VBA in Excel 2000. In my macroI have created variables x and
y, each as
Integer. I use For .. Next to cause the spreadsheet to calculate for
each iteration a result
which appears in a designated cell of the spreadsheet.
I then wish to assign that cell value to the macro variable x. How do
I perform this Copy/Paste operation?
Further, I wish to total all such results for x into the variable y
via the macro line: y=y+x. And then I wish to display the final value
for y as a cell in the spreadsheet. How do I effect that Copy/Paste
operation?

Many thanks.

-- Allen

Loading cell values into macro variables is not a copy/Paste operation.
It's an assignment.
Example:
x = Cells(row, col).Value.

In your case, totalling each cell value in 'y' doesn't require
assigning the value to 'x' beforehand. Example: y = y + Cells(row,
col).Value.

So your macro could just deal with the 'result' it comes up with.
Example:
Cells(row, col).Value = Result: y = y + Result

When done, just assign 'y' to the appropriate cell.
Example:
Cells(row, col).Value = y
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top