Results 1 to 3 of 3

For loop sum cells based on criteria.

Threaded View

Petter120 For loop sum cells based on... 09-04-2014, 03:41 AM
lancer102rus Re: For loop sum cells based... 09-04-2014, 03:51 AM
Petter120 Re: For loop sum cells based... 09-04-2014, 09:04 AM
  1. #1
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Kiruna
    Posts
    163

    For loop sum cells based on criteria.

    Hi


    This code loops from the last row in the third column and looks for value = 91 and when it finds the value =91 it checks the fourth column for value = "Tomt" then it selects the cell in column 4 and extis the loop.


    For x = lr To 1 Step -1
    
    If db.Cells(x, 3) = 91 And db.Cells(x, 5) = "Tomt" Then
        db.Cells(x, 4).Select
        
        
        
        Exit Sub
    End If
    
    Next x
    What i want to do know i is from the selected cell "previous loop" start to loop from selected cell to lastrow and sum every value in column 4 if the value 91 is true in column 3.
    This is what i got so far:

    For i = 1 To lr
    If db.Cells(x, 3) = 91 Then db.Cells(x, 4). ???
    
    End If
    
    Next i
    This is the whole code:
    Sub tomt_senast_tid()
    Dim db As Worksheet
    
    Set db = ThisWorkbook.Sheets("db")
    
    lr = db.Cells(Rows.Count, 1).End(xlUp).Row
    
    For x = lr To 1 Step -1
    
    If db.Cells(x, 3) = 91 And db.Cells(x, 5) = "Tomt" Then
        db.Cells(x, 4).Select
        
        
        
        Exit Sub
    End If
    
    Next x
    
    For i = 1 To lr
    If db.Cells(x, 3) = 91 Then db.Cells(x, 4). ???
    
    End If
    
    Next i
    
    End Sub
    Best regards
    Petter
    Last edited by Petter120; 09-06-2014 at 03:59 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Run / loop through cells and delete based on criteria
    By Coeus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-16-2014, 04:37 PM
  2. [SOLVED] Loop through named range backwards and populate based on criteria from adjacent cells
    By CDEG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2013, 05:56 AM
  3. [SOLVED] Loop to find cells based on criteria, enter formula into next empty column
    By cschoyer in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-10-2012, 03:32 PM
  4. Advancing outer Loop Based on criteria of inner loop
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2005, 01:05 PM
  5. Loop through cells and add rows based on multiple criteria
    By Northern Hybrid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2005, 06:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1