Help with VBA code to delete certain cells based on an offset

facfour

New Member
Joined
Jun 3, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello all:

I need some help with automating some clean-up code.

I have a spreadsheet (see attached snippet) with a set number of columns, but the number of rows can change considerably.

What I'd love the code to do is:

Start in column D, find each entry (going down) that is NOT the Primary Borrower and delete the associated cell value in Column G (Exposure), looping until the only entries left under exposure are related to the Primary Borrower.

I imagine this would employ the offset function perhaps, but I'd love any ideas you have.

Thanks in advance!
 

Attachments

  • example.jpg
    example.jpg
    161.3 KB · Views: 12

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub facfour()
   With Range("G3", Range("G" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("If(@="""","""",if(" & .Offset(, -3).Address & "<>""Primary Borrower"","""",@))", "@", .Address))
   End With
End Sub
 
Upvote 0
Solution
Hi & welcome to MrExcel.
How about
VBA Code:
Sub facfour()
   With Range("G3", Range("G" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("If(@="""","""",if(" & .Offset(, -3).Address & "<>""Primary Borrower"","""",@))", "@", .Address))
   End With
End Sub
Holy Cow! Brilliant! Thanks so much!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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