+ Reply to Thread
Results 1 to 3 of 3

Thread: Help for loop vba

  1. #1
    Registered User
    Join Date
    04-13-2011
    Location
    Cyprus
    MS-Off Ver
    Excel 2003
    Posts
    2

    Help for loop vba

    Dear all I am trying to write a vba with no luck. I want in column k to change the values according the values in column g
    Please anybody can help with the following, it seems right to me but i doesn't do anything.

    Private sub loopthrough()
    
    for i = 3 to 100 
    
    vartest = (Members.cells("G",i).value)
    
    Select case vartest    
           case "15 DAYS"        
    
    varresult = "31"    
    
    case "1 MONTH"        
    
    varresult = "50"    
    
    case "3 MONTHS"        
    
    varresult = "135"  
    
    case "6 MONTHS"        
    
    varresult = "235"    
    
    case "12 MONTHS"        
    
    varresult = "430"  
    
    case "18 MONTHS"        
    
    varresult = "615"    
    
    case else        
    
    varresult = ""
    
    end select
    
    Members.cells("K",i).formula = varresult
    
    Next i
    
    end sub
    Last edited by teylyn; 08-22-2011 at 04:55 AM. Reason: added code tags

  2. #2
    Forum Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,151

    Re: Help for loop vba

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    I'll add the code tags this time, but please remember to use them from now on.
    Last edited by teylyn; 08-22-2011 at 04:54 AM.

  3. #3
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,247

    Re: Help for loop vba

    This should work

    Private Sub loopthrough()
    
        For i = 3 To 100
        
            vartest = (Members.Cells("G", i).Value)
            
            Select Case vartest
                Case "15 DAYS":     varresult = 31
                
                Case "1 MONTH":     varresult = 50
                
                Case "3 MONTHS":    varresult = 135
                
                Case "6 MONTHS":    varresult = 235
                
                Case "12 MONTHS":   varresult = 430
                
                Case "18 MONTHS":   varresult = 615
                
                Case Else:          varresult = ""
            End Select
            
            Members.Cells("K", i).Value = varresult
        Next i
    End Sub
    What do you get?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0