Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Select case

Status
Not open for further replies.

emyxd

MIS
Jul 1, 2010
1
US
Check whole column and add problem VBA select case on excel?
Sub TheSelectCase4()

Select Case Range("A").Value

Case 10247700, 10431454, 10465916, 11794934


Range("c1").Value = Range("A1").Value + Range("B1").Value
Case Else

Range("B1").Value = 0

End Select

End Sub

it's only looping through one cell. I want it to look through the whole column. Then add the fields to the right of the column it's checking together. like if it found '10247700' in column A twice, the numbers(only those corresponding to the true fields) in column B should add up.

helpppp please!!
 



Hi,

Looping? you have no loop!
Code:
Sub TheSelectCase4()
    Dim r As Range
    
    For Each r In Range(Cells(1, "A"), Cells(1, "A").End(xlDown))
        Select Case r.Value
        
            Case 10247700, 10431454, 10465916, 11794934
            
                Cells(r.Row, "C").Value = r.Value + Cells(r.Row, "B").Value
                
            Case Else
                
                Cells(r.Row, "B").Value = 0
        
        End Select
    Next

End Sub

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top