+ Reply to Thread
Results 1 to 2 of 2

macro over range, deleting blanks

  1. #1
    Dirk
    Guest

    macro over range, deleting blanks

    Dear all

    I want to delete blanks at the end over a range of strings. I wrote the
    following macro but I am not sure about the right usage of rng. help
    would be appreciated.

    Sub delblanks()
    Dim count As Integer, rng As range
    rng = InputBox("Please type the range")
    count = 0
    range(rng).Select
    Do While Right(rng, 1) = " "
    count = count + 1
    rng = Left(rng, Len(rng) - 1)
    Loop
    MsgBox ("there were " + count + " changes made")
    End Sub

    Dirk


  2. #2
    Bob Phillips
    Guest

    Re: macro over range, deleting blanks

    Dirk,

    Try this. It allows the user to select the range with the mouse

    Set rng = Application.Inputbox("Please select the mouse", Type:=8)
    For Each cell in rng
    cell.Value = Trim(cell.Value)
    Next cell

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Dirk" <dirknbr@googlemail.com> wrote in message
    news:1132931133.113813.292000@g47g2000cwa.googlegroups.com...
    > Dear all
    >
    > I want to delete blanks at the end over a range of strings. I wrote the
    > following macro but I am not sure about the right usage of rng. help
    > would be appreciated.
    >
    > Sub delblanks()
    > Dim count As Integer, rng As range
    > rng = InputBox("Please type the range")
    > count = 0
    > range(rng).Select
    > Do While Right(rng, 1) = " "
    > count = count + 1
    > rng = Left(rng, Len(rng) - 1)
    > Loop
    > MsgBox ("there were " + count + " changes made")
    > End Sub
    >
    > Dirk
    >




+ 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