Data exchange between macro and spreadsheet

  • Thread starter Thread starter alfurfine
  • Start date Start date
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
 
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
 
Back
Top