How can Excel rewrite a copied cell value based on my instructions?

xThomi

New Member
Joined
Mar 8, 2018
Messages
5
Hi

I am currently copying information from a different source into Excel. The source gives me values which i want to rewrite. An example would be that the source gives me a value in column M that is "1". But i need to rewrite that information into "Completed". This is now done manually but i was hoping there could be some kind of macros that could help me automate this.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You can record a macro for that.
Turn macro recorder on, then Ctrl H put 1 in the Find What box & put Completed in the Replace with box, click Replace All & finally stop the recorder.
 
Upvote 0
Hi FLuff

Thnx!


I tried this now but when i run the macro (i've set it to run on command Ctrl+p) then i get a Run-time error '91' Object variable or With block variable not set

Sub Macro2()
'
' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+P
'
Cells.Find(What:="1", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Replace What:="1", Replacement:="Complete", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.FindNext(After:=ActiveCell).Activate
End Sub
 
Upvote 0
Looks like you clicked Find & then replace, rather than replace all.
Try
Code:
Sub Macro1()
    Range("M:M").Replace What:="1", Replacement:="Complete", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
End Sub
 
Upvote 0
It works now, thank you!

A follow up question: Is it possible to run the macro automatically everytime a line is copied in?
 
Upvote 0
You could use this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
   Range("M:M").Replace What:="1", Replacement:="Complete", LookAt:=xlPart, _
      SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
      ReplaceFormat:=False
Application.EnableEvents = True
End Sub
It needs to go in the sheet module rather than a standard module.
Right click the tab you want it to work on, select view code & paste the code into the window that opens up.
BUT be aware that this will run whenever you make any changes to that sheet.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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