+ Reply to Thread
Results 1 to 12 of 12

Slow Macro Modify

Hybrid View

johncena Slow Macro Modify 04-05-2010, 03:16 AM
royUK Re: Slow Macro Modify 04-05-2010, 03:33 AM
johncena Re: Slow Macro Modify 04-05-2010, 04:43 AM
royUK Re: Slow Macro Modify 04-05-2010, 05:15 AM
Marcol Re: Slow Macro Modify 04-05-2010, 06:50 AM
johncena Re: Slow Macro Modify 04-05-2010, 07:32 AM
Marcol Re: Slow Macro Modify 04-05-2010, 07:58 AM
johncena Re: Slow Macro Modify 04-05-2010, 08:14 AM
Marcol Re: Slow Macro Modify 04-05-2010, 09:41 AM
johncena Re: Slow Macro Modify 04-05-2010, 10:21 AM
Marcol Re: Slow Macro Modify 04-05-2010, 12:34 PM
johncena Re: Slow Macro Modify 04-06-2010, 12:40 AM
  1. #1
    Forum Contributor
    Join Date
    02-14-2010
    Location
    oman
    MS-Off Ver
    Excel 2003
    Posts
    384

    Post Slow Macro Modify

    dear friends below two macro i want to run one time.for that i have used " call " function.this macro work fine but very slow.pls any body can combined this two macros & remake to work fast.thanks.
    Sub Sticker()
    Dim LR As Long, i As Long
    LR = Range("C" & Rows.Count).End(xlUp).Row
    For i = 2 To LR
        If Range("E" & i).Value <> "" Then Range("H" & i).ClearContents
        If Range("C" & i).Value = "AMBATTUR B" Then
            With Range("D" & i)
                If InStr(.Value, "-") <> 0 Then .Value = Right(.Value, Len(.Value) - InStr(.Value, "-"))
            End With
        End If
    Next i
    
    Call Lotremove
    
    End Sub
    Sub Lotremove()
    
    Dim cell As Range
    For Each cell In Range("M3", Range("M" & Rows.Count).End(xlUp))
        cell.Value = Val(cell.Value)
        cell.Offset(0, -7).NumberFormat = "0"
    Next cell
    
    Dim LastRow As Long, r As Range
    LastRow = Range("L" & Rows.Count).End(xlUp).Row
    On Error Resume Next
    Set r = Range("E3:E" & LastRow & ",H3:H" & LastRow).SpecialCells(xlCellTypeBlanks)
    
    If Not r Is Nothing Then r.FormulaR1C1 = "'"
    On Error GoTo 0
    End Sub
    Last edited by johncena; 04-06-2010 at 12:40 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Slow Macro Modify

    This looks the same as your previous post
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    02-14-2010
    Location
    oman
    MS-Off Ver
    Excel 2003
    Posts
    384

    Post Re: Slow Macro Modify

    dear sir royUK.pls check my previous post.these macros not same..
    http://www.excelforum.com/excel-prog...very-slow.html

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Slow Macro Modify

    So why not apply what you learned from the previous post?

  5. #5
    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: Slow Macro Modify

    Try this first

    Sub Sticker()
        Dim LR As Long
        
        LR = Range("C" & Rows.Count).End(xlUp).Row
        
        Range("E1:H" & LR).AutoFilter Field:=1, Criteria1:="="
        Range("H2:H" & LR).ClearContents
        Range("E1:H" & LR).AutoFilter
        
        Range("C1:D" & LR).AutoFilter Field:=1, Criteria1:="AMBATTUR B"
        Range("D2:D" & LR).Replace What:="*-", Replacement:="", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        Range("C1:D" & LR).AutoFilter
        
        Call Lotremove
    
    End Sub

    If this does what you want, we can then address Lotremove.

    P.S. This is very similar to the last stages of your previous post on the subject.

    http://www.excelforum.com/excel-prog...very-slow.html

    The main difference is the use of AutoFilter

    Cheers

  6. #6
    Forum Contributor
    Join Date
    02-14-2010
    Location
    oman
    MS-Off Ver
    Excel 2003
    Posts
    384

    Re: Slow Macro Modify

    sir Marcol it's not working.if column "E" has any values then same row column "H" value should clear.but column "E" don't have any value then column "H" values no need to clear.this macro cleaning column "H" all values.

  7. #7
    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: Slow Macro Modify

    Try changing this line

    Range("E1:H" & LR).AutoFilter Field:=1, Criteria1:="="
    To
    Range("E1:H" & LR).AutoFilter Field:=1, Criteria1:="<>"

    Is that what you want?

  8. #8
    Forum Contributor
    Join Date
    02-14-2010
    Location
    oman
    MS-Off Ver
    Excel 2003
    Posts
    384

    Re: Slow Macro Modify

    thanks a lot sir Marcol now it's work very well very fast.this is last answer or u will do something to second macro also..

  9. #9
    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: Slow Macro Modify

    Re: Sub Lotremove()

    1/. Are you just wanting to clear all formulae in Column "M" and replace with their values?

    2/. What are you trying to do with Columns "E" & "H" ?
    Seems to me that they were dealt with in Sub Sticker(), No?

  10. #10
    Forum Contributor
    Join Date
    02-14-2010
    Location
    oman
    MS-Off Ver
    Excel 2003
    Posts
    384

    Post Re: Slow Macro Modify

    Quote Originally Posted by Marcol View Post
    Re: Sub Lotremove()

    1/. Are you just wanting to clear all formulae in Column "M" and replace with their values?

    2/. What are you trying to do with Columns "E" & "H" ?
    Seems to me that they were dealt with in Sub Sticker(), No?
    column "M" i want to keep only first 6 characters.
    Columns "E" & "H" all empty cells should fill with " ' " apostrophe.

  11. #11
    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: Slow Macro Modify

    Just what this has to do with keeping the first 6 characters in a cell, I don't know?

    For Each cell In Range("M3", Range("M" & Rows.Count).End(xlUp))
        cell.Value = Val(cell.Value)
        cell.Offset(0, -7).NumberFormat = "0"
    Next cell

    However try this
    Sub LotRemove()
        Dim LastRow As Long
        
        LastRow = Range("M" & Rows.Count).End(xlUp).Row
        
        ' Temporary helper Column
        Range("IV2").Formula = "=Trim(Left(M2,6))"
        Range("IV2:IV" & LastRow).FillDown
        Range("IV2:IV" & LastRow).Copy
        ' Destination Column
        Range("M2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
                                 SkipBlanks:=False, Transpose:=False
        ' Clear Temporary helper Column
        Range("IV2:IV" & LastRow).Clear
        
        Range("M2:M" & LastRow).Offset(0, -7).NumberFormat = "0"
        
        LastRow = Range("L" & Rows.Count).End(xlUp).Row
        Range("E1:E" & LastRow).AutoFilter Field:=1, Criteria1:="="
        Range("E2:E" & LastRow).Replace What:="", Replacement:="'", LookAt:=xlPart, _
                        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                        ReplaceFormat:=False
        Range("E1:E" & LastRow).AutoFilter
        
        Range("H1:H" & LastRow).AutoFilter Field:=1, Criteria1:="="
        Range("H2:H" & LastRow).Replace What:="", Replacement:="'", LookAt:=xlPart, _
                        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                        ReplaceFormat:=False
        Range("H1:H" & LastRow).AutoFilter
        
    End Sub

    1/. What purpose does filling blank cells with an apostrophe serve? I'm curious.

    2/. There is nothing in this code, as can clearly be seen, that could not been done without a macro,

    3/. For one-offs you should consider using Excel as it comes straight out of the box.


    Hope this helps.

  12. #12
    Forum Contributor
    Join Date
    02-14-2010
    Location
    oman
    MS-Off Ver
    Excel 2003
    Posts
    384

    Re: Slow Macro Modify

    thanks u very much sir Marcol.now this macro work very fast.thanks a lot.i have try to give REP+ but it's saying (You must spread some Reputation around before giving it to Marcol again).sorry for that.

+ 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