NEWBIE Writing a for loop using relative range

wporterfield

New Member
Joined
Jan 12, 2005
Messages
2
Basically I am trying to write a FOR loop that keeps moving down a column of letters. The letters stand for different categories that the dollar amount should be added to.

The Procedure should:

1. Look at the letter

2. If it matches the letter in the IF statement it should add the amount two columns to the left to a specific cell on a different sheet (The cell that is being added to will remain constant for that particular letter code.)

The cell being added to will be on a different sheet in the same book. However, if it's a lot of trouble to explain how to do that, we can just assume it will be on the same sheet for now.

3. Move down to the next row using the same columns.

4. Repeat the process

It seems like it would be simple... and I'm sure it's posted somewhere but I'm having a hard time finding it.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Not entirely sure if this is what your talking about but this example may help...

Code:
Sub Example()
Dim Rng As Range, c As Range

'set a range representing the area to loop through
Set Rng = Range("C1:C10")

For Each c In Rng
'if value = letter V
    If c.Value = "V" Then
'Sum 2 columns 2 the left and put total in next blank cell in col A in sheet 2
        Sheets("Sheet2").Range("A65536").End(xlUp).Offset(1, 0).Value = _
            WorksheetFunction.Sum(c.Offset(0, -1), c.Offset(0, -2))
    End If
Next c

End Sub
 
Upvote 0

Forum statistics

Threads
1,202,987
Messages
6,052,939
Members
444,617
Latest member
Rush1984

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