Find last row based on text in a cell

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
261
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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,039
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Is there any data in Column A below the word FABRIC?
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,039
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
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.
 
Solution

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
261
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
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,039
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
You're welcome
 

Watch MrExcel Video

Forum statistics

Threads
1,129,361
Messages
5,635,808
Members
416,884
Latest member
leeshjay

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
Top