Find last row based on text in a cell

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
370
Hi, can the code below be revised to find the last row up to a cell with a specific word, "FABRIC", in column A? I have a variable section I want to copy but it has blank rows separating portions of it, so the find last row stops at the first blank line. Below is a snapshot of my table.

Thanks

Sub TOT_FAB()

Application.ScreenUpdating = False
Range("A8:C" & Range("A8").End(xlDown).Row).Copy

Sheets.Add(After:=Sheets("PARTS LIST")).name = "TOT FAB"

Worksheets("TOT FAB").Range("A3").PasteSpecial Paste:=xlPasteFormulas

Range("C:C").Select
Selection.TextToColumns Destination:=Range("C3"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="X", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Range("E3").Select

Columns("A:A").AutoFit
Columns("B:B").HorizontalAlignment = xlCenter
Columns("C:E").HorizontalAlignment = xlLeft
Columns("B:B").ColumnWidth = 5
Columns("C:D").ColumnWidth = 6

Range("A1") = "DESCRIPTION"
Range("B1") = "QUA"
Range("C1") = "WID"
Range("D1") = "LEN"

Application.ScreenUpdating = True

End Sub
VBA Code:

1618069743316.png
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Is there any data in Column A below the word FABRIC?
 
Upvote 0
Try...
VBA Code:
Range("A8:C" & Columns(1).Find("FABRIC", , xlValues, , xlByRows, xlPrevious).Row).Copy
if the word FABRIC only appears once in Column A.
 
Upvote 0
Solution
Try...
VBA Code:
Range("A8:C" & Columns(1).Find("FABRIC", , xlValues, , xlByRows, xlPrevious).Row).Copy
if the word FABRIC only appears once in Column A.
Hi, it worked. I added a "-1" to not include the "fabric" line. It worked as well. Thanks!

Range("A8:C" & Columns(1).Find("FABRIC", , xlValues, , xlByRows, xlPrevious).Row - 1).Copy
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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