Quickly select the 10th non-empty cell in column "A"

harzer

Board Regular
Joined
Dec 15, 2021
Messages
159
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,
In column "A", I have a very large number of empty and non-empty cells, how can we quickly select the 10 non-empty cells in this column "A".
I've put together a little macro that does the job, but it takes a long time to run.
How can we do this more efficiently.
I want a solution in VBA, no formula please.
Thanks in advance.

Here is the Macro.

VBA Code:
Private Sub CommandButton2_Click

    Application.ScreenUpdating = False

    Dim lastRow As Long
    Dim Count As Integer
    Dim Row As Integer

    Count = 0
    Row = 1
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row

    Do While Row <= lastRow
        If Not (Cells(Row, 1) = "") Then
            Count = Count + 1
        End If
        Row = Row + 1
                If Count = 10 Then
                     Range("A" & Row).Select
                End If
    Loop

    Application.ScreenUpdating = True

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Give this a try

VBA Code:
Private Sub CommandButton2_Click()
  Dim a As Variant
  Dim i As Long, myCount As Long
  
  With Range("A2", Range("A" & Rows.Count).End(xlUp))
    a = .Value
    Do
      i = i + 1
      If Len(a(i, 1)) > 0 Then myCount = myCount + 1
    Loop Until myCount = 10 Or i = UBound(a)
    If myCount = 10 Then
      .Cells(i).Select
    Else
      MsgBox "Ten cells not found"
    End If
  End With
End Sub
 
Upvote 0
Solution
Hello Peter_SSs,
Thank you for your efficiency with the proposed code, in fact, it works quickly and gives me the desired result.
Thanks again.
Greetings.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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