VBA - Find text and replace with value of cell above it

jmcginley3

New Member
Joined
Mar 28, 2018
Messages
14
I'm trying to figure out how I can use Cells.Replace along with Offset to locate and replace the cells that contain the text "Auto Adjustments" and replace it with the value of the cell directly above it.


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]450[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Auto Adjustments[/TD]
[TD]<--- this Cell is changed to the value of the cell right above it (450)[/TD]
[/TR]
[TR]
[TD]564[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]45433[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]56788[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9084[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Auto Adjustments[/TD]
[TD]<---- this Cell is changed to the value of the cell right above it (9084)[/TD]
[/TR]
[TR]
[TD]56165[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8765[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Auto Adjustments[/TD]
[TD]<---- this Cell is changed to the value of the cell right above it (8765)[/TD]
[/TR]
</tbody>[/TABLE]

Can I use this and insert some kind of offset coding into the Replacement?

Code:
    Cells.Replace What:="Auto Adjustments", Replacement:="?????", LookAt:= xlPart, SearchOrder:=xlByRows
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
How about
Code:
Sub replaceSpec()
With Range("a2", Range("A" & Rows.Count).End(xlUp))
   .Value = Evaluate(Replace(Replace("if(@=""Auto Adjustments"",#,@)", "@", .Address), "#", .Offset(-1).Address))
End With
End Sub
 
Upvote 0
Hey that worked! Thanks for your help! Now I'm off to dissect and understand what it's doing. I've just recently jumped into using macros since it helps a great deal with my new job.
 
Upvote 0
Glad to help& thanks for the feedback
 
Upvote 0
Sorry to jump in on your thread. I'm still new to this but can some on help me how to set goal seek must be in ascending


For example cell B83 "set cell" is the sum of B71:B82

and cell B85 is the "to value"

and cell b70 is "by changing cell"


also, cell b71 is a hard code cell
cell b72 =B71*(1+$B$70)
cell b73 =B72*(1+$B$71)

and so far


thank you
 
Upvote 0
@ttran123
As this is a completely different question, please start your own thread.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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