Search for two words execute code to change values

andymalan

Board Regular
Joined
Feb 22, 2017
Messages
128
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
Dear friends,
Search Column I for the word “shelf”, when “shelf” is found, check if the cell directly below contains the word “width”. If the two conditions are met, carry out the code instructions.
If they are NOT met, continue to search col I till there is no more data.

1674126331964.png


VBA Code:
Dim r As Integer
Dim c As Integer

r = ActiveCell.Row
c = ActiveCell.Column

'search for "Shelf" search for any changed values in length,width and depth
Application.DisplayAlerts = False
Set rng = Range("I2:I1500") ' RANGE TO SEARCH
specificText = "Shelf" ' text to search for
For Each cell In rng.Cells
If UCase(cell.Value) Like "*" & UCase(specificText) & "*" Then
cell.Offset(1, 2).Select
Selection.Copy
cell.Offset(0, -3).Select
ActiveSheet.Paste
cell.Offset(1, 5).Select
Selection.Copy
cell.Offset(0, -4).Select
ActiveSheet.Paste
cell.Offset(1, 8).Select
Selection.Copy
cell.Offset(0, -2).Select
ActiveSheet.Paste
End If
Next

I'm always very grateful for your help.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Use and IF within your loop like this:
VBA Code:
If (UCase(cell.Value) = "SHELF") And (UCase(cell.Offset(1, 0).Value) = "WIDTH") Then
 
Upvote 0
Solution
Use and IF within your loop like this:
VBA Code:
If (UCase(cell.Value) = "SHELF") And (UCase(cell.Offset(1, 0).Value) = "WIDTH") Then
Thank you Joe. I was so sure it could be done, and I am more than pleased that you have taught me how to do it. Thank you thank you thank you.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,757
Members
449,094
Latest member
dsharae57

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