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.?
 
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
I will try this then
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I will try this then
It is replacing the columns only as before but not the first row.
With Union(Sheets("SalesData").Range("1:1"), Sheets("SalesData").Range("D:D"))
.Replace "&", "&amp", xlPart, , False, , False, False
End With
With Union(Sheets("SalesData").Range("1:1"), Sheets("SalesData").Range("D:D"))
.Replace "&amp", "&", xlPart, , False, , False, False
End With
 
Upvote 0
Are you sure you have some & characters in row 1?
Because it works fine for me.
 
Upvote 0
I got it. Actually it was & with a semi colon. ?
Thanks Fluff. You are one of the Gods of excel.
Thanks for your patience and help.?
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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