Find Replace Loop with last row

tcnt9176

Board Regular
Joined
Jun 23, 2008
Messages
223
I have a loop I am trying to use to find all blank cells in a Column and enter a formula in those blank cells. The loop works but never stops b/c there are blanks in the Column after the data set. I will post the code that I normally use and then what I have tried to fix it without success. Thanks for any help!!!


Started with:
Code:
    Do
    If Not Columns("P:P").Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        True, SearchFormat:=False) Is Nothing Then
        Columns("P:P").Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        True, SearchFormat:=False).Activate
        ActiveCell.Select
        ActiveCell.FormulaR1C1 = "=RC[1]"
        ActiveCell.Copy
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
        ActiveCell.Offset(0, 1).ClearContents
    Else
        Exit Do
    End If
Loop

I have tried this:
Code:
    LastRow = Range("A65536").End(xlUp).Row
 
    Do
    If Not Columns("P:P" & LastRow).Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        True, SearchFormat:=False) Is Nothing Then
        Columns("P:P & LastRow").Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        True, SearchFormat:=False).Activate
        ActiveCell.Select
        ActiveCell.FormulaR1C1 = "=RC[1]"
        ActiveCell.Copy
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
        ActiveCell.Offset(0, 1).ClearContents
    Else
        Exit Do
    End If
Loop

And this changing columns to Range:
Code:
    LastRow = Range("A65536").End(xlUp).Row
 
    Do
    If Not Range("P:P" & LastRow).Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        True, SearchFormat:=False) Is Nothing Then
        Range("P:P & LastRow").Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        True, SearchFormat:=False).Activate
        ActiveCell.Select
        ActiveCell.FormulaR1C1 = "=RC[1]"
        ActiveCell.Copy
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
        ActiveCell.Offset(0, 1).ClearContents     
    Else
        Exit Do
    End If
Loop
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
tcnt9176,

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


Change the P1 to the beginning row.


Code:
    LastRow = Range("A65536").End(xlUp).Row
 
    Do
    If Not Range([B]"P1:P" & LastRow[/B]).Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        True, SearchFormat:=False) Is Nothing Then
        Range([B]"P1:P" & LastRow[/B])..Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        True, SearchFormat:=False).Activate
        ActiveCell.Select
        ActiveCell.FormulaR1C1 = "=RC[1]"
        ActiveCell.Copy
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
        ActiveCell.Offset(0, 1).ClearContents     
    Else
        Exit Do
    End If
Loop
 
Upvote 0

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

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