Consulting

Results 1 to 6 of 6

Thread: macro to delete text

  1. #1

    macro to delete text

    hi all,

    i need a macro to delete the word "NULL" when it appears in a cell in work sheet.

    I used macro recorder to come up wit the following code. The problem is whenever i attempt to run this it takes over 4 hours and never completes.

     Range("I10:BH10").Select
     Range(Selection, Selection.End(xlDown)).Select
     Range("I10:BH25000").Select
     Selection.Replace What:="NULL", Replacement:=" ", LookAt:=xlPart, _
     SearchOrder:=xlByRows, MatchCase:=False
    Does anyone have another solution I can try that maybe faster?

    Many thanks,

    Nicko

  2. #2
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    u can call this macro
    here i am checking with colum A


    Sub delete()
    Dim calcmode As Long
    Dim ViewMode As Long
    Dim myStrings As Variant
    Dim FoundCell As Range
    Dim I As Long
    Dim myRng As Range
    Dim sh As Worksheet

    With Application
    calcmode = .Calculation
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
    End With

    'We use the ActiveSheet but you can also use Sheets("MySheet")
    Set sh = ActiveSheet

    'We search in column A in this example
    Set myRng = sh.Range("A:A")

    'Add more search strings if you need
    myStrings = Array("null")


    With sh

    'We select the sheet so we can change the window view
    .Select

    'If you are in Page Break Preview Or Page Layout view go
    'back to normal view, we do this for speed
    ViewMode = ActiveWindow.View
    ActiveWindow.View = xlNormalView

    'Turn off Page Breaks, we do this for speed
    .DisplayPageBreaks = False

    'We will search the values in MyRng in this example
    With myRng

    For I = LBound(myStrings) To UBound(myStrings)
    Do
    Set FoundCell = myRng.Find(What:=myStrings(I), _
    After:=.Cells(.Cells.Count), _
    LookIn:=xlFormulas, _
    LookAt:=xlWhole, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False)


    'Use xlPart If you want to search in a part of the FoundCell
    'If you use LookIn:=xlValues it will also delete rows with a
    'formula that evaluates to "null"
    If FoundCell Is Nothing Then
    Exit Do
    Else
    FoundCell.Cells.Clear
    End If
    Loop
    Next I

    End With

    End With

    ActiveWindow.View = ViewMode
    With Application
    .ScreenUpdating = True
    .Calculation = calcmode
    End With



    End Sub

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    You could record a macro of using Find/Replace to find NULL and replace with nothing.

  4. #4
    I originally tried a find/replace macro to find NULL and replace with nothing, but unfortunately was taking over 4 hours and crashing.

    Shamsam1's macro is working, but also operating pretty slowly.

  5. #5
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    check for given range dont check whole column the it will work fast

  6. #6
    just adjusted it so it works for the range not the whole column and it is working faster.

    I need to check across 50 columns so that is why it takes so long.

    If i run the macro for one column at a time it is very fast, but this means have to keep adjusting the macro for the next column.

    Is there a way to adjust it so it works down one column then moves onto the next, until there is no columns left to check?

Posting Permissions

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