Macro Select All Rows until Formula is FALSE

tatertot

New Member
Joined
Apr 10, 2016
Messages
31
Hello Excel world,

I want to perform the LEN formula in a macro for column D. I want to test "=LEN(D:D)=9" and where the last TRUE is highlight all rows above it, including the last TRUE. I have scoured the internet with absolutely zero success in knowing if this is possible or not.

Can this be done? I am wanting to copy the rows, if it is possible, and paste to a new worksheet.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Give this a try in a copy of your workbook.

Rich (BB code):
Sub CopyOnLength()
  Dim a As Variant
  Dim i As Long
  
  a = Range("D1", Range("D" & Rows.Count).End(xlUp).Offset(1)).Value
  Do Until Len(a(i + 1, 1)) <> 9
    i = i + 1
  Loop
  If i > 0 Then
    Application.ScreenUpdating = False
    ActiveSheet.Copy After:=ActiveSheet
    Rows(i + 1).Resize(UBound(a) - i).Delete
    Application.ScreenUpdating = True
  Else
    MsgBox "No rows to copy"
  End If
End Sub
 
Last edited:
Upvote 0
Peter, thank you so much for your reply to this thread with code!! I inserted the code into my macro but was unlucky in having it find what it should and be able to copy that data.
 
Upvote 0
.. was unlucky in having it find what it should and be able to copy that data.
I don't understand this. Can you expand on it and/or provide some small sample data to demonstrate?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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