Find second blank cell after P14 and format its contents as a percentage

suremac

New Member
Joined
Jan 27, 2014
Messages
49
Greetings,

I need to find the second blank cell after cell 'P14' and format its contents as a percentage. I am presently using this code:

Range("P31").NumberFormat = "0%"

How can I specify the range so that it finds and formats the second blank row after P14 as a percentage? The problem occurs because I have data continuously appending a table, which shifts all the data down, and causes the wrong data points to be formatted.

Thanks,
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Well, the cell itself needs to be formatted in the aforementioned manner, so that any data put there will be formatted as a percentage.

Thanks,
 
Upvote 0
This will find and format the second blank cell in column P after P14.
Code:
Sub FindSecondBlankAfterP14()
Dim lR As Long, c As Range
lR = Range("P" & Rows.Count).End(xlUp).Row
If WorksheetFunction.CountA(Range("P15:P" & lR)) <= Range("P15:P" & lR).Rows.Count - 2 Then
    'there are at least two empty cells from P15 to last filled cell in column P
    For Each c In Range("P15:P" & lR - 1)
        If IsEmpty(c) Then
            ct = ct + 1
            If ct = 2 Then
                c.NumberFormat = "0%"
                Exit For
        End If
    Next c
ElseIf WorksheetFunction.CountA(Range("P15:P" & lR)) = Range("P15:P" & lR).Rows.Count - 1 Then
    'only one empty cell between P15 and last filled cell in column P
    Cells(lR + 1, "P").NumberFormat = "0%"
Else
    Cells(lR + 2, "P").NumberFormat = "0%"
End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,585
Messages
6,125,679
Members
449,248
Latest member
wayneho98

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