Macro to Find and Replace Cell References

TooZippy

Board Regular
Joined
Dec 30, 2018
Messages
70
I used this macro and it works to a certain extent. At first, I was having it look for "$M", "$N", "$O", “$P”, “$Q”, “$R”, “$S”,“$T”, “$U”. These cell references are the result after deleting a few columns in another spreadsheet. They are t be replaced with "$Q", "$R", "$S", “$T”, “$U”, “$V”, “$W”,“$X”, “$Y” (in that order) in a range of formulas off to the right.

It did not work since I had "$Q", "$R", "$S", “$T”, “$U” in both the Find and Replace. I took that out and it worked except that the order of the cell references in the formulas was mixed up. I need to have $Y cell reference at the far right of the formulas because I have a sum formula adding up the columns to the left of this column. Can anybody help please?

Code:
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]Sub Find_and_Replace()[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000] [/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]Dim Rng As Range[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]Dim InputRng As Range, ReplaceRng As Range[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]xTitleId = "KutoolsforExcel"[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]Set InputRng = Application.Selection[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]Set InputRng = Application.InputBox("Formulas to Fix ",xTitleId, InputRng.Address, Type:=8)[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]Set ReplaceRng = Application.InputBox("Find and Replace Values:", xTitleId, Type:=8)[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]Application.ScreenUpdating = False[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]For Each Rng In ReplaceRng.Columns(1).Cells[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]    [/COLOR][COLOR=#000000]InputRng.Replacewhat:=Rng.Value, replacement:=Rng.Offset(0, 1).Value[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]Next[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]Application.ScreenUpdating = True[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][COLOR=#000000]End Sub[/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT]

Thank you,

Jared Z.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Here is a table of what I am trying to find and replace along with the results with the above formula. Can anybody help please?

Thank you,

Jared Z.

[TABLE="width: 256"]
<colgroup><col width="64" style="width:48pt" span="4"> </colgroup><tbody>[TR]
[TD="width: 64, bgcolor: transparent"]Find[/TD]
[TD="width: 64, bgcolor: transparent"]Replace[/TD]
[TD="width: 64, bgcolor: transparent"]Result[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]$I[/TD]
[TD="bgcolor: transparent"]$Q[/TD]
[TD="bgcolor: transparent"]$U[/TD]
[TD="bgcolor: transparent"]Col. 1[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]$J[/TD]
[TD="bgcolor: transparent"]$R[/TD]
[TD="bgcolor: transparent"]$V[/TD]
[TD="bgcolor: transparent"]Col. 2[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]$k[/TD]
[TD="bgcolor: transparent"]$S[/TD]
[TD="bgcolor: transparent"]$W[/TD]
[TD="bgcolor: transparent"]Col. 3[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]$L[/TD]
[TD="bgcolor: transparent"]$T[/TD]
[TD="bgcolor: transparent"]$X[/TD]
[TD="bgcolor: transparent"]Col. 4[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]$M[/TD]
[TD="bgcolor: transparent"]$U[/TD]
[TD="bgcolor: transparent"]$Y[/TD]
[TD="bgcolor: transparent"]Col. 5[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]$N[/TD]
[TD="bgcolor: transparent"]$V[/TD]
[TD="bgcolor: transparent"]$R[/TD]
[TD="bgcolor: transparent"]Col. 6[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]$O[/TD]
[TD="bgcolor: transparent"]$W[/TD]
[TD="bgcolor: transparent"]$S[/TD]
[TD="bgcolor: transparent"]Col. 7[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]$P[/TD]
[TD="bgcolor: transparent"]$X[/TD]
[TD="bgcolor: transparent"]$T[/TD]
[TD="bgcolor: transparent"]Col. 8[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]$Q[/TD]
[TD="bgcolor: transparent"]$Y[/TD]
[TD="bgcolor: transparent"]$U[/TD]
[TD="bgcolor: transparent"]Col. 9
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

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