Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Conditional DeleteRow, if portion of string found

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Conditional DeleteRow, if portion of string found

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Conditional DeleteRow, if portion of string found

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Conditional DeleteRow, if portion of string found

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
  #5   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Conditional DeleteRow, if portion of string found

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Conditional DeleteRow, if portion of string found

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
  #7   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Conditional DeleteRow, if portion of string found

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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Conditional DeleteRow, if portion of string found

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
match value within any portion of lookup string in range Hile Excel Worksheet Functions 3 October 16th 09 12:58 PM
Finding string and color the found string Agustus Excel Programming 1 September 20th 06 07:51 PM
Bold a portion of concatenated string joeeng Excel Discussion (Misc queries) 1 December 8th 05 08:26 PM
Extracting A Portion Of A String MWS Excel Programming 4 November 21st 05 06:22 PM
How to replace defined portion of string ExcelMonkey Excel Programming 2 July 19th 05 12:21 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"