Replace with copy and paste

Hansulet

Board Regular
Joined
Jan 24, 2013
Messages
172
Office Version
  1. 2021
Platform
  1. Windows
I need a macro to replace the cells

My code is:
Selection.Replace What:="03.2018", Replacement:="04.2018", LookAt:=xlPart _
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

But instead "03.2018" should be what i copied from the cell A1 and instead "04.2018" should be what i copied from the cell A2
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
maybe
Rich (BB code):
Selection.Replace What:=Range("A1").value, Replacement:=Range("A2").value, LookAt:=xlPart _
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
 
Last edited:
Upvote 0
Dear Fazza
Please help to edit this my code I would like to another sheet my code working but not good
please review again
Thank
Lotto beginner vba

Private Sub CommandButton1_Click()

Worksheets("3G U21").Range("A2:A100000").Select
Selection.Replace what:="U21-", replacement:=" ", lookat:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Worksheets(ActiveSheet.Index + 1).Select
Worksheets("3G U08").Range("A2:A100000").Select
Selection.Replace what:="U08-", replacement:=" ", lookat:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Worksheets(ActiveSheet.Index + 1).Select
Worksheets("4G L21").Range("A2:A100000").Select
Selection.Replace what:="L21-", replacement:=" ", lookat:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

MsgBox "DONE"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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