Macros

Copper Contributor
Dear sir,
I am a beginner for macros. I want to create a macro to copy a part of text from one cell and append it to the text in another cell. How to go about this?
Pl help.
8 Replies

@Hda_1957 

Please provide detailed information.

@Hda_1957 

 

As Mr Hans Vogelaar (@Hans Vogelaar) gave you as advice, I can only recommend it to you,

please add a file (without sensitive data) and describe your plan on it.

This means that you can be helped more quickly

and the best possible solution tailored to your needs can be offered.

So everyone is helped...Help to be helped.

 

* It's always good to add your operating system and Excel version.

 

Nevertheless, here is a little VBA code for an easy copy / paste with VBA.

 

Public Sub Copy_Paste()
    With Worksheets("Sheet1")
        .Range(.Cells(1, 1), .Cells(10, 3)).Copy Destination:=.Cells(11, 4)
    End With
End Sub

'Change the cell / column according to your needs.

 

I would be happy to know if I could help.

 

Nikolino

I know I don't know anything (Socrates)

@Hans Vogelaar 

Thanks Hans for your reply.

 ABC
1Krishna Yadav  
2  Rama 

I wanted to create a Macro to cut/copy text  "Krishna" from cell A1 and paste and append it to "Rama" in cell say C2, to make it "Rama Krishna" in cell C2.

That is the only requirement.

I think I have made my problem clear.

Expect solution.

Regards, 

Hemant

@NikolinoDE 

Dear Nikolino, Thanks for reply.

 

 ABC
1Krishna Yadav  
2  Rama 

I wanted to create a Macro to cut/copy text  "Krishna" from cell A1 and paste and append it to "Rama" in cell say C2, to make it "Rama Krishna" in cell C2.

That is the only requirement.

I think I have made my problem clear.

Expect solution.

Regards, 

Hemant

@Hda_1957 

For example:

Sub MoveText()
    Dim strText As String
    strText = "Krishna"
    Range("A1").Value = Trim(Replace(Range("A1").Value, strText, ""))
    Range("C2").Value = Range("C2").Value & " " & strText
End Sub

@Hda_1957 

 

Thank you for the feedback

 

No problem, I just pointed it out to you so that you should get the best possible solution.

So Please do not misunderstand my contribution.

 

So far i see Mr.@Hans Vogelaar  give you a solution.
If you like Mr. @Hans Vogelaar  solution, please mark it with a like or as the best answer to Mr. @Hans Vogelaar  contribution,
it will be beneficial to more Community members reading here.

 

 

Thank you for your understanding and patience.

 

Nikolino

I know I don't know anything (Socrates)

@Hans Vogelaar

Dear Hans,

Thanks for your interest in my problem.

Your solution is working. But it moves the text "krishna" only. It works every where wherever there is text "Krishna". But I want to move the word which I select after going to any particular cell in the sheet. It can be any word. Explained further below.

 ABC
1Krishna Yadav Rama 
2satish pulekar jerry
3john dsouza Kamat

When I will go to cell A1 and select "Krishna" and press the shortcut key for the macro, it should cut "Krishna" and cell C1 should become "Rama Krishna".

Similarly, 

When I go to cell A2 and select "pulekar" and press the shortcut key for the macro, it should cut "pulekar " and cell C2 should become "jerry pulekar".

When I go to cell A3 and select "john" and press the shortcut key for the macro, it should cut "john" and cell C3 should become "Kamat".

I have to do such job for about 500 cells which are discontinuous. ( separated from each other)

Regards,

Hemant

 

@Hda_1957 

That is not possible. When you select a word in a cell, Excel is in edit mode. Macros cannot be run while Excel is in edit mode.

We could change the macro to prompt for the word to move. Would that be OK?