PDA

View Full Version : Cut and paste question



andytpl
08-23-2007, 03:11 AM
I like to cut the text up to the first space of the active cell and paste this cut text onto the cell to the left of the active cell.
Appreciate and help

daniel_d_n_r
08-23-2007, 03:29 AM
ActiveCell.Offset(0, -1).Value = ActiveCell.Value
ActiveCell.Clear

just an idea
there could be abetter way to handle this.

andytpl
08-23-2007, 05:09 AM
Your codes only cut the whole text and pasting over to the cell on the left. What I hope to accomplish is to cut the text up to the first spacing and then paste this cut text to cell on the left of the active cell and the remaining of the non cut text stay in the active cell.

mdmackillop
08-23-2007, 06:08 AM
Sub MoveBit()
ActiveCell.Offset(, -1) = Split(ActiveCell)(0)
ActiveCell = Trim(Right(ActiveCell, (Len(ActiveCell)) - Len(Split(ActiveCell)(0))))
End Sub

p45cal
08-23-2007, 06:18 AM
Sub blah()
mySpace = InStr(ActiveCell.Value, " ")
ActiveCell.Offset(0, -1) = Left(ActiveCell.Value, mySpace - 1)
ActiveCell.Value = Mid(ActiveCell.Value, mySpace + 1, Len(ActiveCell.Value))
End Subor

Sub blah2()
a = Split(ActiveCell.Value, " ", 2)
ActiveCell.Offset(0, -1) = a(0)
ActiveCell = a(1)
End Sub

mdmackillop
08-23-2007, 07:28 AM
Hi P45,
Re Blah2, there may be more than one space in the cell.

daniel_d_n_r
08-23-2007, 07:41 AM
Sub MoveFirstWord()
x = Left(ActiveCell.Value, InStr(1, mywords, " "))
ActiveCell.Offset(0, -1).Value = CStr(x)
ActiveCell.Value = Right(ActiveCell.Value, (Len(mywords) - Len(x)))
End Sub



ha ha I spent a bit of time over this so I thought I would post a reply anyway.
even though the post has already been answered.
nice one mdmackillop,,

cheers

p45cal
08-23-2007, 08:59 AM
Hi P45,
Re Blah2, there may be more than one space in the cell.
It doesn't matter, the 2 handlles that.
p45cal

mdmackillop
08-23-2007, 09:27 AM
It doesn't matter, the 2 handlles that.
p45cal
Thanks for that. I'd never noticed the limit parameter. That will make life easier in a few of my codes.

mdmackillop
08-23-2007, 09:31 AM
A single line solution, thanks to P45

Sub blah3()
ActiveCell.Offset(0, -1).Resize(1, 2) = Split(ActiveCell.Value, " ", 2)
End Sub

andytpl
08-23-2007, 04:39 PM
Guys,

Thanks for all the help and solution suggested. Really appreciate it.