vba help - Find specific string and replace top cell value

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

Need vba help to find "Agst Ref" or "New Ref." if found via loop
Fill Top cells Values.
Highlighted those cells value in Red Color.


Input Data is in ColumnA.
Expected Output ColumnB.

Below is a Table.
Book2
AB
1Input ColumnsExpected Output
2xyz Limitedxyz Limited
3Agst Refxyz Limited
4Agst Refxyz Limited
5Agst Refxyz Limited
6Agst Refxyz Limited
7Union Bank of IndiaUnion Bank of India
8PQR Paints Ltd.PQR Paints Ltd.
9New RefPQR Paints Ltd.
10Union Bank of IndiaUnion Bank of India
11Interest of Cash Credit - BankInterest of Cash Credit - Bank
12Union Bank of IndiaUnion Bank of India
13ABC LimitedABC Limited
14Agst RefABC Limited
15Union Bank of IndiaUnion Bank of India
16TDS A.Y. 2021-22TDS A.Y. 2021-22
17New RefTDS A.Y. 2021-22
18Venkys (India) Ltd.Venkys (India) Ltd.
19Agst RefVenkys (India) Ltd.
20Agst RefVenkys (India) Ltd.
21Agst RefVenkys (India) Ltd.
Sheet1



Thanks
mg
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi mg,

Try below code ...
VBA Code:
Sub test()

Dim c As Range

For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
   If c.Value = "Agst Ref" Or c.Value = "New Ref" Then c.Offset(-1).Copy c
Next

End Sub
 
Upvote 0
Hi mse330,

Perfect ! thanks for your help, it is giving correct output.

Need one more help,

Output is showing in Same Column, Can we take it into Column B.





Thanks
mg
 
Upvote 0
Try now ...
VBA Code:
Sub test()

Dim c As Range

Columns(1).Copy [B1]

For Each c In Range("B2", Range("B" & Rows.Count).End(xlUp))
   If c.Value = "Agst Ref" Or c.Value = "New Ref" Then c.Offset(-1).Copy c
Next

End Sub
 
Upvote 0
Hi mse330,

I already tried this it has worked ! ok will continue this logic as its giving correct output.


Thanks for your help! (y) ?



Thanks
mg
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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