For and for each loops

knburch

New Member
Joined
Feb 25, 2017
Messages
1
I need help with this assignment for my excel/VBA class. I have been struggling with VBA

1. manually enter 1 to 100 in cells A1 to A100
2. write a for loop that makes use of the offset property to sum the numbers in every 5th cell starting with A3. The loop should stop once A100 has been reached
3. Write a for each loop that colors every even-numbered cell in your range blue
4. write a for loop that colors every odd numbered cell in your range yellow

any help would be appreciated! :)
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Mr. Excel discourages us from doing students assignments. Now if you can show us what you already have and just need one little bit of help we may be able to give you a little help. Show us what you have already done.
I need help with this assignment for my excel/VBA class. I have been struggling with VBA

1. manually enter 1 to 100 in cells A1 to A100
2. write a for loop that makes use of the offset property to sum the numbers in every 5th cell starting with A3. The loop should stop once A100 has been reached
3. Write a for each loop that colors every even-numbered cell in your range blue
4. write a for loop that colors every odd numbered cell in your range yellow

any help would be appreciated! :)
 
Upvote 0
Sub format()


Dim i As Integer
Dim total As Long
Range("a3").Select
Dim cel As Range


Do Until ActiveCell.Value = ""
total = WorksheetFunction.Sum(Range("a1:" & ActiveCell.Address))
ActiveCell.Offset(0, 1).Value = total
ActiveCell.Offset(4, 0).Select
Loop

For Each cel In Range("a1:a100")

If cel.Value Mod 2 = 0 Then
cel.Interior.Color = vbBlue
Else
cel.Interior.Color = vbYellow
End If
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,331
Messages
6,124,311
Members
449,152
Latest member
PressEscape

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