ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sort out data with VBA (https://www.excelbanter.com/excel-programming/363648-sort-out-data-vba.html)

JOUIOUI

Sort out data with VBA
 
I have a spreadsheet that will very in row count every day. I only want to
keep the rows that contain the text "Assets". This criteria will be in
column B. I have an existing macro that adds the page formatting. Can I add
code to this macro to delete everything that does not include Assets in
Column B. Thanks so much.

Chip Pearson

Sort out data with VBA
 
Try something like

Dim LastRow As Long
Dim RowNdx As Long
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "B"), "assets", vbTextCompare) < 0
Then
Rows(RowNdx).Delete
End If
Next RowNdx



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"JOUIOUI" wrote in message
...
I have a spreadsheet that will very in row count every day. I
only want to
keep the rows that contain the text "Assets". This criteria
will be in
column B. I have an existing macro that adds the page
formatting. Can I add
code to this macro to delete everything that does not include
Assets in
Column B. Thanks so much.




JOUIOUI

Sort out data with VBA
 
Thanks Chip, this looks like it would work for me but I get this Compile
Error, " Expected Line Number or label statement or end statement". I'm not
sure what this means. Did I so something wrong, I did a straight copy and
paste into my existing macro

"Chip Pearson" wrote:

Try something like

Dim LastRow As Long
Dim RowNdx As Long
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "B"), "assets", vbTextCompare) < 0
Then
Rows(RowNdx).Delete
End If
Next RowNdx



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"JOUIOUI" wrote in message
...
I have a spreadsheet that will very in row count every day. I
only want to
keep the rows that contain the text "Assets". This criteria
will be in
column B. I have an existing macro that adds the page
formatting. Can I add
code to this macro to delete everything that does not include
Assets in
Column B. Thanks so much.





Tom Ogilvy

Sort out data with VBA
 
Might have been a wordwrap problem:

Sub DeleteRows()
Dim LastRow As Long
Dim RowNdx As Long
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "B"), "assets", _
vbTextCompare) < 0 Then
Rows(RowNdx).Delete
End If
Next RowNdx
End sub

--
Regards,
Tom Ogilvy


"JOUIOUI" wrote:

Thanks Chip, this looks like it would work for me but I get this Compile
Error, " Expected Line Number or label statement or end statement". I'm not
sure what this means. Did I so something wrong, I did a straight copy and
paste into my existing macro

"Chip Pearson" wrote:

Try something like

Dim LastRow As Long
Dim RowNdx As Long
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "B"), "assets", vbTextCompare) < 0
Then
Rows(RowNdx).Delete
End If
Next RowNdx



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"JOUIOUI" wrote in message
...
I have a spreadsheet that will very in row count every day. I
only want to
keep the rows that contain the text "Assets". This criteria
will be in
column B. I have an existing macro that adds the page
formatting. Can I add
code to this macro to delete everything that does not include
Assets in
Column B. Thanks so much.






All times are GMT +1. The time now is 04:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com