Copied cell value to another cell with message

ozimosko

New Member
Joined
Mar 25, 2022
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,

First of all English is not my native language. Sorry for my misspellings.

Below is the screenshot of the simplified excel of the macro I need to write.
After the user enters data in the "Receipt No"(C2) field, I need to automatically add "messagetext" + "Receipt No" to the "Description"(B2) field.

The values to be entered in the "Receipt No" cell are not fixed. The user can enter 1 piece of data or 1000 pieces of data. Therefore, it is needed to enter the loop. It will be written in the "Description" field by extracting(copied) the data in the "Receipt No" section and adding a message to the beginning of the retrieved data.

Also, can we do these operations without pressing any button?

I've just started writing VBA and I'm having a lot of trouble. Can you help me please?

1648190951396.png
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Right click on sheet name, click "View Code", then paste below code into edit window:
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
Target.Offset(0, -1).Value = "message " & Target.Value
End Sub
 
Upvote 0
Right click on sheet name, click "View Code", then paste below code into edit window:
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
Target.Offset(0, -1).Value = "message " & Target.Value
End Sub
OMG Was it that simple? I've been searching for loops for a week :)
Thank you very much!

By the way, "message" remains after data is written and deleted in column C. It's not a big deal. If users want, I'll continue to search.
1648198405959.png
 
Upvote 0
OMG Was it that simple? I've been searching for loops for a week :)
Thank you very much!

By the way, "message" remains after data is written and deleted in column C. It's not a big deal. If users want, I'll continue to search.
View attachment 60895
Right click on sheet name, click "View Code", then paste below code into edit window:
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
Target.Offset(0, -1).Value = "message " & Target.Value
End Sub
Also if I copy paste the code gives an error "Run-Time Error 13, Type mismatch" :( How we can fix this? My guess is that users will copy data from another source and paste it into this excel.
 
Upvote 0
just simple
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
Target.Offset(0, -1).Value = IIf(Target.Value = "", "", "message " & Target.Value)
End Sub
 
Upvote 0
Also if I copy paste the code gives an error "Run-Time Error 13, Type mismatch" :( How we can fix this? My guess is that users will copy data from another source and paste it into this excel.
Do you mean paste into column C?
I tested and it seem worked for me.
 
Upvote 0
Do you mean paste into column C?
I tested and it seem worked for me.
Yes, it works if you paste a single data into column C as you said. However, if more than one data is pasted, it gives the error I mentioned above.

For example, if I paste the numbers below into column C, I get an error
123
321
423
543
1648199254970.png
 
Upvote 0
So you were coping and pasting a range, not single cell, weren't you?
OK I know the situation and will come back later.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top