Macro to select Row as well as any particular column

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello,
Sheets("Sheet1").Activate
Columns("D:D").Select
Selection.Replace What:="&", Replacement:="&", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("A2").Select

This formula selects and replaces & in the column D
I want it to select the first full row also along with column D
what is the code to be added and where.?
 
Sorry, Just got a little confused. There are 2 similar codes in the Macro. One in the beginning and one in the end.
1. Columns("D:D").Select
Selection.Replace What:="&", Replacement:="&", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
2.
Columns("D:D").Select
Selection.Replace What:="&", Replacement:="&", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
It should replace twice, so that in the end the data is at its original display.
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Did the code I supplied do what you wanted?
 
Upvote 0
Do you have the code laid out as per post#5, or in one line like your quote in in post#6?
Sorry. Just got a little confused. I have 2 codes in the macro one to replace & with & and the other to replace & to &. So that the orginal data stays the same after import.
1.
Columns("D:D").Select
Selection.Replace What:="&", Replacement:="&", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
2.
Columns("D:D").Select
Selection.Replace What:="&", Replacement:="&", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
 
Upvote 0
That is nothing more than a duplicate of post#11
Please answer my question.
 
Upvote 0
Sorry. Just got a little confused. I have 2 codes in the macro one to replace & with & and the other to replace & to &. So that the orginal data stays the same after import.
1.
Columns("D:D").Select
Selection.Replace What:="&", Replacement:="&", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
2.
Columns("D:D").Select
Selection.Replace What:="&", Replacement:="&", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Let me try again
 
Upvote 0
Sorry, Fluff, I am not getting you.
 
Upvote 0
Take the code form post#5 & run it (without changing anything) & see if it does what you want.
 
Upvote 0
This will do both replacements
VBA Code:
Sub Rajesh()
   With Union(Sheets("sheet1").Range("1:1"), Sheets("Sheet1").Range("D:D"))
      .Replace "&", "&amp", xlPart, , False, , False, False
   End With
   'do something
   With Union(Sheets("sheet1").Range("1:1"), Sheets("Sheet1").Range("D:D"))
      .Replace "&amp", "&", xlPart, , False, , False, False
   End With
End Sub
 
Upvote 0
With Union(Sheets("SalesData").Range("1:1"), Sheets("SalesData").Range("D:D"))
.Replace "&amp", "&", xlPart, , False, , False, False
End With
The name of the sheet is SalesData. As there were multiple sheets I selected a common name. When I run F8, it doesn't replace & with &
 
Upvote 0

Forum statistics

Threads
1,215,836
Messages
6,127,175
Members
449,368
Latest member
JayHo

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