Results 1 to 2 of 2

Thread: Slow if else?!?!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Location
    boston
    Posts
    22
    Can anyone advise on how to speed up the following code (it is running through 9000 records of MS Excel and takes about 14 minutes)?

    Dim Num as Range
    For Each Num In ActiveSheet.Range("A1:A9000")
    If Num.Value = "Thing1" Then
    Num.EntireRow.Copy
    Sheets(1).Select
    Rows("1:1").Select
    Selection.Insert Shift:=xlDown

    ElseIf Num.Value = "Thing2" Then
    Num.EntireRow.Copy
    sheets(2).Select
    Rows("1:1").Select
    Selection.Insert Shift:=xlDown

    'ElseIf... through 40 more "Things"; 8 more sheets!!!

    I thought of select case but going down that road did not seem to add any value. Any help is greatly appreciated!

    Best regards.

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Try:

    Code:
    Dim strNumValue as String
    ...
    strNumValue = Num.Value
    ...
    If strNumValue = "Thing1" Then
    ...
    Else If strNumValue = "Thing2" Then
    ...
    ...
    Hope that helps,
    Josh

Posting Permissions

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



Click Here to Expand Forum to Full Width