PC Review


Reply
Thread Tools Rate Thread

Conditional DeleteRow, if portion of string found

 
 
=?Utf-8?B?Q0xS?=
Guest
Posts: n/a
 
      3rd Aug 2007
Hi All......

I have two macros, the first one works to delete rows if a cell in column H
is empty.

Sub DeleterowsNONAME()
Dim lastrow As Long, r As Long
Application.ScreenUpdating = False
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
For r = lastrow To 2 Step -1
If Cells(r, "h") = "" Then
Rows(r).EntireRow.Delete
End If
Next r
Application.ScreenUpdating = True
End Sub

The second one, I'm trying to modify so if the word "trust" is found
anywhere in the cell string, to delete the entire row.....this one don't work.


Sub DeleterowsTRUST()
Dim lastrow As Long, r As Long
Application.ScreenUpdating = False
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
For r = lastrow To 2 Step -1
If Cells(r, "h") = "*TRUST*" Then
Rows(r).EntireRow.Delete
End If
Next r
Application.ScreenUpdating = True
End Sub


Any help would be appreciated............using XL97
Vaya con Dios,
Chuck, CABGx3

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      3rd Aug 2007
If Cells(r, "h").value like "*TRUST*" Then
or

if lcase(Cells(r, "h").value) like lcase("*TRUST*") Then



CLR wrote:
>
> Hi All......
>
> I have two macros, the first one works to delete rows if a cell in column H
> is empty.
>
> Sub DeleterowsNONAME()
> Dim lastrow As Long, r As Long
> Application.ScreenUpdating = False
> lastrow = Cells(Rows.Count, "a").End(xlUp).Row
> For r = lastrow To 2 Step -1
> If Cells(r, "h") = "" Then
> Rows(r).EntireRow.Delete
> End If
> Next r
> Application.ScreenUpdating = True
> End Sub
>
> The second one, I'm trying to modify so if the word "trust" is found
> anywhere in the cell string, to delete the entire row.....this one don't work.
>
> Sub DeleterowsTRUST()
> Dim lastrow As Long, r As Long
> Application.ScreenUpdating = False
> lastrow = Cells(Rows.Count, "a").End(xlUp).Row
> For r = lastrow To 2 Step -1
> If Cells(r, "h") = "*TRUST*" Then
> Rows(r).EntireRow.Delete
> End If
> Next r
> Application.ScreenUpdating = True
> End Sub
>
> Any help would be appreciated............using XL97
> Vaya con Dios,
> Chuck, CABGx3


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      3rd Aug 2007
Sub DeleterowsTRUST()
Dim lastrow As Long, r As Long
s = "TRUST"
Application.ScreenUpdating = False
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
For r = lastrow To 2 Step -1
If InStr(Cells(r, "h").Value, s) > 0 Then
Rows(r).EntireRow.Delete
End If
Next r
Application.ScreenUpdating = True
End Sub

--
Gary''s Student - gsnu200735
 
Reply With Quote
 
=?Utf-8?B?Q0xS?=
Guest
Posts: n/a
 
      3rd Aug 2007
Thank you Sir, it works fine.....appreciate the help.

Vaya con Dios,
Chuck, CABGx3



"Gary''s Student" wrote:

> Sub DeleterowsTRUST()
> Dim lastrow As Long, r As Long
> s = "TRUST"
> Application.ScreenUpdating = False
> lastrow = Cells(Rows.Count, "a").End(xlUp).Row
> For r = lastrow To 2 Step -1
> If InStr(Cells(r, "h").Value, s) > 0 Then
> Rows(r).EntireRow.Delete
> End If
> Next r
> Application.ScreenUpdating = True
> End Sub
>
> --
> Gary''s Student - gsnu200735

 
Reply With Quote
 
=?Utf-8?B?Q0xS?=
Guest
Posts: n/a
 
      3rd Aug 2007
Thank you Sir......both work fine.......I "like" them.

Vaya con Dios,
Chuck, CABGx3


"Dave Peterson" wrote:

> If Cells(r, "h").value like "*TRUST*" Then
> or
>
> if lcase(Cells(r, "h").value) like lcase("*TRUST*") Then
>
>
>
> CLR wrote:
> >
> > Hi All......
> >
> > I have two macros, the first one works to delete rows if a cell in column H
> > is empty.
> >
> > Sub DeleterowsNONAME()
> > Dim lastrow As Long, r As Long
> > Application.ScreenUpdating = False
> > lastrow = Cells(Rows.Count, "a").End(xlUp).Row
> > For r = lastrow To 2 Step -1
> > If Cells(r, "h") = "" Then
> > Rows(r).EntireRow.Delete
> > End If
> > Next r
> > Application.ScreenUpdating = True
> > End Sub
> >
> > The second one, I'm trying to modify so if the word "trust" is found
> > anywhere in the cell string, to delete the entire row.....this one don't work.
> >
> > Sub DeleterowsTRUST()
> > Dim lastrow As Long, r As Long
> > Application.ScreenUpdating = False
> > lastrow = Cells(Rows.Count, "a").End(xlUp).Row
> > For r = lastrow To 2 Step -1
> > If Cells(r, "h") = "*TRUST*" Then
> > Rows(r).EntireRow.Delete
> > End If
> > Next r
> > Application.ScreenUpdating = True
> > End Sub
> >
> > Any help would be appreciated............using XL97
> > Vaya con Dios,
> > Chuck, CABGx3

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      3rd Aug 2007
Just to add to Gary's Student's post...

You may want to use
If InStr(1, Cells(r, "h").Value, s, vbtextcompare) > 0 Then
To avoid any problem with case.

CLR wrote:
>
> Thank you Sir, it works fine.....appreciate the help.
>
> Vaya con Dios,
> Chuck, CABGx3
>
> "Gary''s Student" wrote:
>
> > Sub DeleterowsTRUST()
> > Dim lastrow As Long, r As Long
> > s = "TRUST"
> > Application.ScreenUpdating = False
> > lastrow = Cells(Rows.Count, "a").End(xlUp).Row
> > For r = lastrow To 2 Step -1
> > If InStr(Cells(r, "h").Value, s) > 0 Then
> > Rows(r).EntireRow.Delete
> > End If
> > Next r
> > Application.ScreenUpdating = True
> > End Sub
> >
> > --
> > Gary''s Student - gsnu200735


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?Q0xS?=
Guest
Posts: n/a
 
      3rd Aug 2007
Thaks Dave...........I just "keep on learning".........the guy in the next
cubicle asked me today, "how often do you learn something new in
Excel".......the answer of course was "EVERY DAY".

Vaya con Dios,
Chuck, CABGx3



"Dave Peterson" wrote:

> Just to add to Gary's Student's post...
>
> You may want to use
> If InStr(1, Cells(r, "h").Value, s, vbtextcompare) > 0 Then
> To avoid any problem with case.
>
> CLR wrote:
> >
> > Thank you Sir, it works fine.....appreciate the help.
> >
> > Vaya con Dios,
> > Chuck, CABGx3
> >
> > "Gary''s Student" wrote:
> >
> > > Sub DeleterowsTRUST()
> > > Dim lastrow As Long, r As Long
> > > s = "TRUST"
> > > Application.ScreenUpdating = False
> > > lastrow = Cells(Rows.Count, "a").End(xlUp).Row
> > > For r = lastrow To 2 Step -1
> > > If InStr(Cells(r, "h").Value, s) > 0 Then
> > > Rows(r).EntireRow.Delete
> > > End If
> > > Next r
> > > Application.ScreenUpdating = True
> > > End Sub
> > >
> > > --
> > > Gary''s Student - gsnu200735

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
=?Utf-8?B?ZGFudGVl?=
Guest
Posts: n/a
 
      27th Aug 2007
Wow, that is beautiful. You guys make me look like a VBA preschooler, but
that is just fine with me. What would I do to look for a string in the
entire row, instead of just column H, would I do a bunch of "If" statements
or a Select case structure to find the desired string? I.E.,

For r = lastrow To 2 Step -1
If InStr(Cells(r, "h").Value, s) > 0 Then
Rows(r).EntireRow.Delete
End If
If InStr(Cells(r, "i").Value, s) > 0 Then
Rows(r).EntireRow.Delete
End If
If InStr(Cells(r, "j").Value, s) > 0 Then
Rows(r).EntireRow.Delete
End If
Next r

Or Is there a better, more efficient way?
--
thx for any help.... and again, wow.
dantee.


"Gary''s Student" wrote:

> Sub DeleterowsTRUST()
> Dim lastrow As Long, r As Long
> s = "TRUST"
> Application.ScreenUpdating = False
> lastrow = Cells(Rows.Count, "a").End(xlUp).Row
> For r = lastrow To 2 Step -1
> If InStr(Cells(r, "h").Value, s) > 0 Then
> Rows(r).EntireRow.Delete
> End If
> Next r
> Application.ScreenUpdating = True
> End Sub
>
> --
> Gary''s Student - gsnu200735

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting portion of string RP Microsoft C# .NET 3 27th Dec 2007 06:58 AM
remove portion of string K Microsoft Access VBA Modules 3 11th Dec 2007 11:06 PM
Extracting portion of a string =?Utf-8?B?QnJpYW5QYXVs?= Microsoft Access 7 8th Aug 2006 11:33 PM
extract portion of a string using SQL =?Utf-8?B?cGVkcm8=?= Microsoft Access Queries 6 6th Sep 2005 02:36 AM
Extracting a portion of a string Richard L Rosenheim Microsoft Dot NET 3 17th Feb 2005 08:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:32 AM.