Macro - Fill formula down until adjacent cell contains "string"

JoseJones

New Member
Joined
Aug 3, 2013
Messages
8
I've created the following Macro based on some of the posts on this great forum! It works great, but I'd like to tweak it for another purpose where it would fill the formula down until a cell in column AF had the value "#N/A" or stopped having the value "clean". The #N/A is from a formula result so I'm not sure if or how the Macro would treat this.

Thank you!

Code:
Sub Y_CleanUp3()
'
' Clean Up Bad Data Macro 3
    Dim LR As Integer
    Range("AH2").Formula = "=VLOOKUP(X2,'[Territory by Zip Code.xlsx]Sheet1'!$A$2:$B$135000,2,TRUE)"
    LR = Range("AF" & Rows.Count).End(xlUp).Row
    Range("AH2").AutoFill Destination:=Range("AH2:AH" & LR), Type:=xlFillDefault
    With Range("AH2:AH" & LR)
    End With
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
On "N/A", do you want it to stop filling or just skip that one value? Also, how many rows are we looking at? I'd look into a for loop unless it's a large dataset.
 
Upvote 0
On "N/A", do you want it to stop filling or just skip that one value? Also, how many rows are we looking at? I'd look into a for loop unless it's a large dataset.

Thank you for replying so fast!

I would like it to stop. Right now the macro fills down the column until it sees an empty cell in AF. So, instead of empty empty I'd like it to stop when it either sees "#N/A" or doesn't see "clean" in AF, whatever is easier. The rows are variable length and can have dozens to hundreds of results based on this formula.

Not sure this helps, but my goal is to eventually piece together a few macros to help speed up data cleaning of these records. Right now I'm making specific steps as I'm trying to undstand how to make the macros. Here's the Macro that precedes the one I need help with, and puts "clean" in the cells and then sorts the column to have the records with "clean" at the top. The next step is to do a VLOOKUP and replace values based on rows with "clean" in them.

Code:
Sub Y_CleanBadZips()
'
' Clean Up Bad Zips macro
    Dim LR As Integer
    DateRange = Application.InputBox(Prompt:="What is the date range?")
    Range("AG2").Formula = "=VLOOKUP(AF2,'[" & DateRange & "LATLONG.xlsx]zipcodes'!$B$2:$D$12000,3,FALSE)"
    LR = Range("AF" & Rows.Count).End(xlUp).Row
    Range("AG2").AutoFill Destination:=Range("AG2:AG" & LR), Type:=xlFillDefault
    With Range("AG2:AG" & LR)
    Columns("AG:AG").Select
    Selection.Sort Key1:=Range("AG2"), Order1:=xlDescending, Header:=xlYes, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

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