PDA

View Full Version : Adding text to existing text



FantasticJac
09-24-2007, 06:35 AM
Hey All,

I've only been messing around with VBA for a few days now after finding out how helpful it can be when working with mass quantities of data in excel. I'm currently stuck and can't find an answer. Any help would be greatly appreciated. I feel like it's probably so easy I'm just looking past it, but I've been trying for two days.... Here's my problem.

I'm pasting a chunk of data into excel from an outside program. I've already got the macro I'm creating cutting and pasting the chunk into a string of useable data, but I need to add to the already existing text in one of the fields that I cut and paste. Is there a variable I can put in in place of the red text so it just tacks what I want onto the end of the string? Or is there a formula?... What I've got is below. The text in red will be different every time... all I want to do is add the ".pwf" to whatever text is in that field. Any ideas would be GREATLY appreciated!

Sub test6()
'
' test6 Macro
' Macro recorded 9/24/2007 by ebenm
'
' Keyboard Shortcut: Ctrl+k
'
ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
False
ActiveCell.Offset(2, 1).Range("A1").Select
Selection.Cut
ActiveCell.Offset(-2, -1).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Select
ActiveCell.FormulaR1C1 = _
"TXWEBB_FP525 C3 43-4600 WE Ser1_3 Agua Azul 600 1.pwf"
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.Cut
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(3, -1).Range("A1").Select
Selection.Cut
ActiveCell.Offset(-3, 0).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(1, -1).Range("A1:B3").Select
Selection.ClearContents
ActiveCell.Select
End Sub

Bob Phillips
09-24-2007, 06:44 AM
ActiveCell.Value = ActiveCell.Value & ".pwf"

FantasticJac
09-24-2007, 06:54 AM
Knew it had to be something like that.... Thanks!!!

mdmackillop
09-24-2007, 12:13 PM
Hi Jac,
Welcome to VBAX
FYI, although recorded code shows every step as a Selection and an Action, this is not required in the code. By giving the cell to be Cut, followed by the Destination, the code can be cleaned up which is much more efficient and easier to follow. As you are just starting out, make use of the recorder, but try to weed out the verbiage.
Regards
MD

Sub test6()
ActiveSheet.PasteSpecial Format:="Text"
With ActiveCell
.Offset(2, 1).Range("A1").Cut .Offset(-2, -1)
.Value = .Value & ".pwf"
.Offset(0, 1).Cut .Offset(0, 1)
.Offset(3, -1).Cut .Offset(-3, 0)
.Offset(1, -1).Range("A1:B3").ClearContents
End With
End Sub