+ Reply to Thread
Results 1 to 6 of 6

Insert 19 cells "Shift to the right" if cell contains "->"

  1. #1
    Registered User
    Join Date
    04-04-2005
    Location
    Bahama, NC
    Posts
    59

    Insert 19 cells "Shift to the right" if cell contains "->"

    I have been looking for a sub that can find a cell in column A that has a "->" in it the actuall cell will contain "P->9999999" the only thing consistant is the "->". When it finds the cell I need it to shift 19 cells to the Right.
    Thanks for the help or any ideas,
    Bob

  2. #2
    Registered User
    Join Date
    04-04-2005
    Location
    Bahama, NC
    Posts
    59
    I have this and it works, it inserts cells until it gets out of the range but takes way to long. One at a time. Any one have any ideas on how to get it insert 19 cells at a time or outside the range.


    Sub Macro64()

    With Worksheets("Imported").Range("imp2")
    Set c = .Find("->", LookIn:=xlValues)
    If Not c Is Nothing Then
    firstAddress = c.Address
    Do
    c.Insert Shift:=xlToRight

    Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
    End With

    End Sub

  3. #3
    William Benson
    Guest

    Re: Insert 19 cells "Shift to the right" if cell contains "->"

    Hi,

    You can use this. Remember, the key here is that once the range is found,
    Excel will not find the next range unless you swap the text in the first
    range for something else. Then, at the end, I swap the text back.

    ....Bill

    Sub hhh()
    Dim LoopEnd As Boolean
    Dim SomeRange As Range
    Const Txt = "SomeUnlikelyText"
    Do While Not LoopEnd
    Set SomeRange = Cells.Find(What:="->")
    If SomeRange Is Nothing Then
    LoopEnd = True
    Else
    SomeRange.Value = Application.Substitute(SomeRange.Value, "->", Txt)
    SomeRange.Cut SomeRange.Offset(0, 19)
    End If
    Loop

    Cells.Replace What:=Txt, Replacement:="->", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

    End Sub


    "robertjtucker" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > I have been looking for a sub that can find a cell in column A that has
    > a "->" in it the actuall cell will contain "P->9999999" the only thing
    > consistant is the "->". When it finds the cell I need it to shift 19
    > cells to the Right.
    > Thanks for the help or any ideas,
    > Bob
    >
    >
    > --
    > robertjtucker
    > ------------------------------------------------------------------------
    > robertjtucker's Profile:
    > http://www.excelforum.com/member.php...o&userid=21805
    > View this thread: http://www.excelforum.com/showthread...hreadid=389337
    >




  4. #4
    Registered User
    Join Date
    04-04-2005
    Location
    Bahama, NC
    Posts
    59
    Thanks for that, but I need all the cells next to the cells containinig the "->" to be moved also thats why I wanted to insert so I could shift everything from A:S to start in T:AL
    Thanks again,
    Bob

  5. #5
    William Benson
    Guest

    Re: Insert 19 cells "Shift to the right" if cell contains "->"

    Minor (very) change:

    Sub hhh()
    Dim LoopEnd As Boolean
    Dim SomeRange As Range
    Const Txt = "SomeUnlikelyText"
    Do While Not LoopEnd
    Set SomeRange = Cells.Find(What:="->")
    If SomeRange Is Nothing Then
    LoopEnd = True
    Else
    SomeRange.Value = Application.Substitute(SomeRange.Value, "->", Txt)
    ActiveSheet.Range(SomeRange, SomeRange.Offset(0, 18)).Cut
    SomeRange.Offset(0, 19)
    End If
    Loop

    Cells.Replace What:=Txt, Replacement:="->", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

    End Sub

    "robertjtucker" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Thanks for that, but I need all the cells next to the cells containinig
    > the "->" to be moved also thats why I wanted to insert so I could shift
    > everything from A:S to start in T:AL
    > Thanks again,
    > Bob
    >
    >
    > --
    > robertjtucker
    > ------------------------------------------------------------------------
    > robertjtucker's Profile:
    > http://www.excelforum.com/member.php...o&userid=21805
    > View this thread: http://www.excelforum.com/showthread...hreadid=389337
    >




  6. #6
    Registered User
    Join Date
    04-04-2005
    Location
    Bahama, NC
    Posts
    59
    Thanks Bill it worked real well.
    Appreciate the help,
    Bob

+ 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