ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cell Reference in a Macro (https://www.excelbanter.com/excel-programming/296607-cell-reference-macro.html)

tim

Cell Reference in a Macro
 
I am looping through a macro, testing the contents a data
in column A. If I find a "P" in the first position clomun
A, I want to capture the value, if there is one, in column
C and column D in that row. I want to keep a running
balance of the sum of those values by column.

I am not sure how to reference those cells when I find
a "P" in column A.

Range("A1").Select
For I = 1 to 100
If Left((ActiveCell,1)="P" Then
TotalC = TotalC + ???
TotalD = TotalD + ???

How do I reference the cells in C and D to add the values
to the running totals?

Something like ActiveCell.Offset(0,2).Value?

TIA.

Bob Phillips[_6_]

Cell Reference in a Macro
 

Range("A1").Select
For I = 1 to 100
With ActiveCell
If Left((.Value,1)="P" Then
TotalC = TotalC + .Offset(0,2).Value
TotalD = TotalD + .Offset(0,3).Value
....
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Tim" wrote in message
...
I am looping through a macro, testing the contents a data
in column A. If I find a "P" in the first position clomun
A, I want to capture the value, if there is one, in column
C and column D in that row. I want to keep a running
balance of the sum of those values by column.

I am not sure how to reference those cells when I find
a "P" in column A.

Range("A1").Select
For I = 1 to 100
If Left((ActiveCell,1)="P" Then
TotalC = TotalC + ???
TotalD = TotalD + ???

How do I reference the cells in C and D to add the values
to the running totals?

Something like ActiveCell.Offset(0,2).Value?

TIA.





All times are GMT +1. The time now is 06:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com