+ Reply to Thread
Results 1 to 2 of 2

Find and remove blanks

  1. #1
    Nick London
    Guest

    Find and remove blanks

    I have a sub that is supposed to find and remove blanks from a spreadsheet.
    However it does not work anymore. I do not understand what is wrong with it.
    The pupose of the sub is to search a spreadsheet for blanks and if the
    contents of a cell is purely numeric then replace these blanks with nothing
    e.g. if a cell contains 100 000 000 it shall be replaced by 100000000 but if
    the contents are AA 3 it should not be changed. I might also add that I am
    pasting in the info from another program into the spreadsheet. I do not know
    if that has any importance. The code is:

    Private Sub findAndRemoveBlanks()
    Dim WB As Workbook
    Dim SH As Worksheet
    Dim rng, rCell As Range
    Set WB = ActiveWorkbook
    Set SH = WB.Sheets("Beräkning")
    Set rng = SH.UsedRange

    For Each rCell In rng.Cells
    With rCell
    If Not IsEmpty(.Value) Then
    If Not UCase(.Value) Like "*[A-Z]*" Then
    .Replace What:=" ", Replacement:=""
    End If
    End If
    End With
    Next rCell
    End Sub

    The code works fine if you write something in a cell and then check it but
    it does not seem to work when pasting. If anyone has any idea how to solve
    this I would be most greatful for any assistance that you can give me! Thank
    you!

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Hi theres plenty of stuff here for removing blanks that you should be able to modify, its all self explanatary with worked examples. http://www.mvps.org/dmcritchie/excel/delempty.htm

    Regards,
    Simon

+ 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