+ Reply to Thread
Results 1 to 12 of 12

macro work but very slow

Hybrid View

  1. #1
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: macro work but very slow

    Try this

    Option Explicit
    
    Sub Equal()
        Dim c As Range
        Dim LR As Long, maxLR As Long, colNo As Long
        
        For colNo = Range("D:G").Column To Range("D:G").Column + Range("D:G").Columns.Count - 1
            LR = Cells(Rows.Count, colNo).End(xlUp).Row
            If LR > maxLR Then maxLR = LR
        Next
        LR = maxLR
        
        With Range("D2:G" & LR)
          .Value = Evaluate("IF(ROW(" & .Address & "),clean(trim(" & .Address & ")))")
        End With
        
        LR = Range("J" & Rows.Count).End(xlUp).Row
        For Each c In Range("J2:J" & LR)
           If c.Formula = True Then c.Value = c.Value
        Next c
        
        LR = Range("E" & Rows.Count).End(xlUp).Row
        Range("E2:E" & LR).Replace What:="-", Replacement:="", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
                
        For colNo = Range("D:H").Column To Range("D:H").Column + Range("D:H").Columns.Count - 1
            LR = Cells(Rows.Count, colNo).End(xlUp).Row
            If LR > maxLR Then maxLR = LR
        Next
        LR = maxLR
        
        Range("D2:H" & LR).Replace What:=" ", Replacement:="", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
    
    End Sub
    If this doesn't work

    A sample workbook would help to clear up any guesswork

    Cheers

    EDIT:

    Missing lines

    LR = maxLR
    Sorry for that.

    Better if each section is written as a function.
    Last edited by Marcol; 04-05-2010 at 04:28 AM. Reason: Missed 2No. lines in code

+ 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