Results 1 to 13 of 13

more effective script

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-02-2013
    Location
    Netherlands
    MS-Off Ver
    Office 365 (2013)
    Posts
    268

    more effective script

    Hi All,

    Since I can't get my screen to lock in openoffice (while using VBA), I have to find another way to speed things up.
    As you can see below, my scripting is very very poor and I was wondering how I can speed up the script.

    I was thinking about tricks to let it run faster, but I don't really come up with solutions.


    Sub Resetall()
    
    Dim KZ As Worksheet
    Dim VA As Worksheet
    Dim ws As Worksheet
    Dim iRow As Integer
    Dim Rng As Range
    Dim Aantal As Integer
    
    Set ws = Worksheets("Data")
    Set VA = Worksheets("HulpSheet")
    Set KZ = Worksheets("Klanten")
    
    Aantal = 0
    
    lastRow = VA.Range("A:D").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    For i = 2 To lastRow
     For j = 1 To 5
      VA.Cells(i,j).Value = ""
     Next j
    Next i
    
    lastRow = ws.Range("C:C").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    For i = 3 To lastRow
    iRow = VA.Range("A:A").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
      If len(ws.Cells(i, 3).Value) > 1 then
      Rng = VA.Range("A:A").Find(What:=ws.Cells(i, 3).Value, SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues)
        If not Rng is Nothing then 
        Set Rng = Nothing
        Else
        VA.Cells(iRow, 1).Value = ws.Cells(i, 3).Value
        End If
      End If
    Next i
    
    lastRow = ws.Range("D:D").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    For i = 3 To lastRow
    iRow = VA.Range("B:B").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
      If len(ws.Cells(i, 4).Value) > 1 then
      Rng = VA.Range("B:B").Find(What:=ws.Cells(i, 4).Value, SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues)
        If not Rng is Nothing then 
        Set Rng = Nothing
        Else
        VA.Cells(iRow, 2).Value = ws.Cells(i, 4).Value
        End If
      End If
    Next i
    
    lastRow = ws.Range("E:E").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    For i = 3 To lastRow
    iRow = VA.Range("C:C").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
      If len(ws.Cells(i, 5).Value) > 1 then
      Rng = VA.Range("C:C").Find(What:=ws.Cells(i, 5).Value, SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues)
        If not Rng is Nothing then 
        Set Rng = Nothing
        Else
        VA.Cells(iRow, 3).Value = ws.Cells(i, 5).Value
        End If
      End If
    Next i
    
    lastRow = ws.Range("H:H").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    For i = 3 To lastRow
    iRow = VA.Range("D:D").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
      If len(ws.Cells(i, 8).Value) > 1 then
      Rng = VA.Range("D:D").Find(What:=ws.Cells(i, 8).Value, SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues)
        If not Rng is Nothing then 
        Set Rng = Nothing
        Else
        VA.Cells(iRow, 4).Value = ws.Cells(i, 8).Value
        End If
      End If
    Next i
    
    Aantal = VA.Range("A:D").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    KZ.Cells(3, 3).Value = ""
    KZ.Cells(3, 4).Value = ""
    KZ.Cells(3, 5).Value = ""
    KZ.Cells(3, 6).Value = ""
    KZ.Cells(6, 3).Value = ""
    KZ.Cells(3, 8).Value = Aantal
    Aantal = KZ.Cells.Find(What:=Aantal, SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1 'to get back on worksheet("Klanten")
    
    End Sub
    Last edited by Evolta; 12-04-2013 at 09:14 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help finding the effective rate of return, Where:
    By Relim in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-16-2011, 11:10 AM
  2. Effective Interest Rate formula
    By jonrayworth in forum Excel General
    Replies: 1
    Last Post: 05-08-2009, 01:49 PM
  3. [SOLVED] effective gross income
    By Ror in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-10-2006, 04:20 AM
  4. More effective code
    By Roman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2005, 12:05 PM

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