+ Reply to Thread
Results 1 to 2 of 2

How to make this macro run effeciently/faster?

Hybrid View

hightide How to make this macro run... 06-08-2011, 03:47 PM
pike Re: How to make this macro... 06-09-2011, 06:04 AM
  1. #1
    Registered User
    Join Date
    05-03-2010
    Location
    london, england
    MS-Off Ver
    Excel 2000
    Posts
    3

    How to make this macro run effeciently/faster?

    Hi all,

    Just wanted to know how to make this macro run effeciently/faster?
    I have only put 4 sets of calculations in here, but there are actually
    86 more sets of calculations in the macro.

    Any help or suggestions would be very much appreciated.

    Regareds.


    Private Sub Worksheet_Calculate()
     
        Dim i As Long
        Dim j As Long
        Dim k As Long
        Dim l As Long
        Dim m As Long
        Dim sRow As Long
        Dim eRow As Long
        Dim cCol As Long
        Dim rCol As Long
        Dim oCol As Long
        Dim sCol As Long
    
        sRow = 27  'Start row
        eRow = 277 'End row
        cCol = 19  'Check fine column 
        rCol = 20 'Results trigger column
        oCol = 21 'Choice column
        sCol = 22 'Fine column
    
    
    
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
        For i = sRow To eRow
        	If Cells(i, cCol) < 11 And Cells(i, cCol) > 1 Then
        		For j = sRow To eRow
    	                If Cells(j, cCol) > 10 And Cells(j, cCol) < 10000 Then
                        		Cells(i, rCol) = "FINE"
                        		Cells(i, oCol) = "11"
                        		Cells(i, sCol) = "30000"
                        
                        		Cells(j, rCol) = "FINE"
                        		Cells(j, oCol) = "10000" 
                        		Cells(j, sCol) = "20" 
                    	End If
                	Next j            
            End If
        Next i
    
    For i = sRow To eRow
        	If Cells(i, cCol) < 106 And Cells(i, cCol) > 1 Then
        		For j = sRow To eRow
    	                If Cells(j, cCol) > 105 And Cells(j, cCol) < 176 Then
    				For k = sRow To eRow
    					If Cells(k, cCol) > 175 And Cells(k, cCol) < 263 Then
                        				Cells(i, rCol) = "FINE"
                        				Cells(i, oCol) = "105"
                        				Cells(i, sCol) = "23000"
                        
                        				Cells(j, rCol) = "FINE"
                        				Cells(j, oCol) = "175" 
                        				Cells(j, sCol) = "25" 
    
                        				Cells(k, rCol) = "FINE"
                        				Cells(k, oCol) = "262" 
                        				Cells(k, sCol) = "10" 
    		                	End If
    				Next k
    			End If
                	Next j            
            End If
        Next i
    
    For i = sRow To eRow
        	If Cells(i, cCol) < 187 And Cells(i, cCol) > 1 Then
        		For j = sRow To eRow
    	                If Cells(j, cCol) > 186 And Cells(j, cCol) < 233 Then
    				For k = sRow To eRow
    					If Cells(k, cCol) > 232 And Cells(k, cCol) < 311 Then
    						For l = sRow To eRow
    							If Cells(l, cCol) > 310 And Cells(l, cCol) < 471 Then
                        						Cells(i, rCol) = "FINE"
                        						Cells(i, oCol) = "186"
                        						Cells(i, sCol) = "4000"
                        
                        						Cells(j, rCol) = "FINE"
                        						Cells(j, oCol) = "232" 
                        						Cells(j, sCol) = "500" 
    
                        						Cells(k, rCol) = "FINE"
                        						Cells(k, oCol) = "310" 
                        						Cells(k, sCol) = "8000" 
    						
    								Cells(l, rCol) = "FINE"
                        						Cells(l, oCol) = "470" 
                        						Cells(l, sCol) = "1000" 
    							End If
    						Next l
    		                	End If
    				Next k
    			End If
                	Next j            
            End If
        Next i
    
    For i = sRow To eRow
        	If Cells(i, cCol) < 331 And Cells(i, cCol) > 1 Then
        		For j = sRow To eRow
    	                If Cells(j, cCol) > 330 And Cells(j, cCol) < 396 Then
    				For k = sRow To eRow
    					If Cells(k, cCol) > 395 And Cells(k, cCol) < 491 Then
    						For l = sRow To eRow
    							If Cells(l, cCol) > 490 And Cells(l, cCol) < 661 Then
                        						For m = sRow To eRow
    									If Cells(m, cCol) > 660 And Cells(m, cCol) < 981 Then
                        								Cells(i, rCol) = "FINE"
                        								Cells(i, oCol) = "330"
                        								Cells(i, sCol) = "3000"
                        
                        								Cells(j, rCol) = "FINE"
                        								Cells(j, oCol) = "395" 
                        								Cells(j, sCol) = "2500" 
    
                        								Cells(k, rCol) = "FINE"
                        								Cells(k, oCol) = "490" 
                        								Cells(k, sCol) = "2000" 
    						
    										Cells(l, rCol) = "FINE"
                        								Cells(l, oCol) = "660" 
                        								Cells(l, sCol) = "1005" 
    							
    										Cells(m, rCol) = "FINE"
                        								Cells(m, oCol) = "980" 
                        								Cells(m, sCol) = "1000" 
    									End If
    								Next m
    							End If
    						Next l
    		                	End If
    				Next k
    			End If
                	Next j            
            End If
        Next i
    
    
    With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    
    End Sub
    Last edited by Leith Ross; 06-08-2011 at 04:36 PM. Reason: Added Code Tags

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: How to make this macro run effeciently/faster?

    hightide
    looking like you are repeating the loop over and over writing with each loop?

    why recheck the cells values?
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

+ 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.6.0 RC 1