VBA for a complex If...Then Loop

  • Thread starter Thread starter Fluffy
  • Start date Start date
F

Fluffy

I know it can be done, but I just don't know the syntax.

I want to tell Excel, to check if a range of cells in the a row as a
particular formating, and for each cell with that formatting to make the some
of the numbers in those cell.

I started the programming, but I just don't know how to write the "Then"
part (in cell E15, make the some of all the cell with the matching formating)

Sub test1()
If Feuil59.Range("U15", "AT15").Interior.ColorIndex = 50 Then
E15 = Sum(U15, AT15) ?????
End If
End Sub

Hope I'm clear enough and thanks for your help

Sophie
 
Hi,

I think you may mean this

Sub test1()
Dim MyRange As Range
Set MyRange = Range("U15:AT15")
For Each c In MyRange
If c.Interior.ColorIndex = 50 Then
mytotal = mytotal + c
End If
Next
Range("E15") = mytotal
End Sub


Mike
 

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

Back
Top