Find the next 2 or 3 empty cells in a Column

themick

New Member
Joined
May 26, 2018
Messages
48
I am creating a results page for my macro. The results will vary day to day as data is processed.
I used the method below to find the next empty cell.

QUESTION: how do I modify this to find the next 2 empty cells and then place new data in the third?
Example: Column A1 has data to A10 thus A11 is the first empty cell. I want the macro then to place the next set of results starting in cell A13.
<code class="vb keyword">Sub</code> <code class="vb plain">Macro2()</code>
<code class="vb spaces"> </code><code class="vb keyword">On</code> <code class="vb keyword">Error</code> <code class="vb keyword">Resume</code> <code class="vb keyword">Next</code>
<code class="vb spaces"> </code><code class="vb keyword">Dim</code> <code class="vb plain">xCell </code><code class="vb keyword">As</code> <code class="vb plain">Range</code>
<code class="vb spaces"> </code><code class="vb keyword">For</code> <code class="vb keyword">Each</code> <code class="vb plain">xCell </code><code class="vb keyword">In</code> <code class="vb plain">ActiveSheet.Columns(1).Cells</code>
<code class="vb spaces"> </code><code class="vb keyword">If</code> <code class="vb plain">Len(xCell) = 0 </code><code class="vb keyword">Then</code>
<code class="vb spaces"> </code><code class="vb plain">xCell.</code><code class="vb keyword">Select</code>
<code class="vb spaces"> </code><code class="vb keyword">Exit</code> <code class="vb keyword">For</code>
<code class="vb spaces"> </code><code class="vb keyword">End</code> <code class="vb keyword">If</code>
<code class="vb spaces"> </code><code class="vb keyword">Next</code>
<code class="vb keyword">End</code> <code class="vb keyword">Sub


Thank you for any help provided on this.</code>
 
Maybe
Code:
Sub X_COPYGREATERTHAN_0()
'
'
With Sheets("MONTHLIES")
lr = .Range("K" & Rows.Count).End(xlUp).Row
'   SELECT, FILTER AND COPY COLUMN K 'NUMBERS>0'
    .Columns("K:K").AutoFilter
    .Range("K" & Rows.Count).AutoFilter Field:=1, Criteria1:=">0", _
        Operator:=xlAnd
    If lr > 1 Then
      .Range("K2:K" & lr).SpecialCells(xlVisible).Copy
      Sheets("RESULTS").Range("A" & Rows.Count).End(xlUp).Offset(3).PasteSpecial xlPasteValues
    End If
'   CLEAR THE AUTOFILTER AND SELECTION
    .Columns("K:K").AutoFilter
End With
[COLOR=#FF0000]    Application.CutCopyMode = False[/COLOR]
'  END ON RESULTS SHEET, FIRST EMPTY CELL AFTER LAST OCCUPIED CELL
   Sheets("RESULTS").Select
   Range("A" & Cells.Rows.Count).End(xlUp).Offset(1, 0).Select
     
End Sub

This line:
Application.CutCopyMode = False
I have had mixed results with this at times. I have found I need to select the worksheet by name and then initiate this.
Does the line : With Sheets("MONTHLIES") > is this why the Select Worksheet line not needed?

Also, I have seen it written both ways (with and without) but why the period (.) in front of 'Range...' in the first line:
lr = .Range("K" & Rows.Count).End(xlUp).Row
?
When you have time, thank you again for the help (and education).
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Using With statements is a short cut, so rather than
Code:
lr = Sheets("MONTHLIES").Range("K" & Rows.Count).End(xlUp).Row
'   SELECT, FILTER AND COPY COLUMN K 'NUMBERS>0'
    Sheets("MONTHLIES").Columns("K:K").AutoFilter
    Sheets("MONTHLIES").Range("K" & Rows.Count).AutoFilter Field:=1, Criteria1:=">0", _
        Operator:=xlAnd
You can do it like I showed. The . in front of .Range & .Columns, signifies that it is part of the With
 
Last edited:
Upvote 0
Using With statements is a short cut, so rather than
Code:
lr = Sheets("MONTHLIES").Range("K" & Rows.Count).End(xlUp).Row
'   SELECT, FILTER AND COPY COLUMN K 'NUMBERS>0'
    Sheets("MONTHLIES").Columns("K:K").AutoFilter
    Sheets("MONTHLIES").Range("K" & Rows.Count).AutoFilter Field:=1, Criteria1:=">0", _
        Operator:=xlAnd
You can do it like I showed. The . in front of .Range & .Columns, signifies that it is part of the With

Thank you again!
M
 
Upvote 0

Forum statistics

Threads
1,223,992
Messages
6,175,822
Members
452,672
Latest member
missbanana

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