Search up from last row

M

Miree

I need to modify my code to search from the last row, at the moment it only
goes from the last row there is data in for my specific column(DT), can I
make it start from the last row where there is data from column A but only
searching the column i need(DT)

Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DT"), Cells(Rows.Count, "DT").End(xlUp))

With rng
For i = .Rows.Count To 1 Step -1
If InStr(UCase(.Cells(i)), UCase(UserForm7.TextBox2.Text)) = 0 Then
.Cells(i).EntireRow.Delete
End If
Next i
End With

Thank you in advance
 
J

Jacob Skaria

Dim lngTemp, lngRow

lngRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

For lngTemp = lngRow To 1 Step -1
If InStr(Range("DT" & lngTemp), UCase(UserForm7.TextBox2.Text)) = 0 Then
Activesheet.Cells(lngTemp).EntireRow.Delete
End If
Next lngTemp

If this post helps click Yes
 
M

Miree

sorry this didnt work, what i think might be eaisier(for my simple midnd) is
if you could help me with a code to identify and select the row one down from
the last data point in column A
 
R

Rick Rothstein

Jacob gave you that (well, except for the "one down from" part). Jacob
posted this...

lngRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

which is the row containing the last piece of data in Column A. Since you
want one down from this, just add one to it...

RowAfterLastDataInA = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
 
M

Miree

Im sorry all this coding is new to me, I am trying to learn as I go, and
because of this I dont understand some basics. Most of what I get is copied
and paste from else where, i dont understand what it does but know it does
what i need it to.

What I am trying to do is select the last row + 1 and then apply this to it
Cells.Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = ".."

although this line finds the row i need, how can i get it to select it?

RowAfterLastDataInA = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
 
J

Jacob Skaria

Will give you an example
If I want to select Range(A1:A12) mention that as

Range("A1:A" & variable).Select


If this post helps click Yes
 
J

Jacob Skaria

Thanks Rick

Dear Miree..Sorry, you have not mentioned about Selection.FormulaR1C1 = ".."
in your initial post. The code which we have posted will satisfy the
requirement mentioned "Search up from last row"..


If this post helps click Yes
 
M

Miree

I understand that but what i dont understand it is if i dont know what range
i want to select how do i tell it to select the last row(in A) +1
 
J

Jacob Skaria

Please try this

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("A1:A" & lngLastRow +1).Select

If this post helps click Yes
 
M

Miree

had to modify slightly to just do last row, but works perfectly now, thank
you very super much to both of you.
 
J

Jacob Skaria

Not sure whether you have seen this post

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("A1:A" & lngLastRow +1).Select

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top