PC Review


Reply
Thread Tools Rate Thread

Delelting previous row

 
 
Novice Lee
Guest
Posts: n/a
 
      14th Aug 2008
What I am trying to do is, check if Row 5, Column D has "SB" in the cell. If
there is a "SB" in the cell, delete the row above it. I have done a search on
deleting row most of the posting were for deleting blank lines and the such
so they weren't much help to me. I am still trying to learn this stuff as
fast as I can.

Thanks
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      14th Aug 2008
hi,,

Giving an answer that you can develop into more meaaningful code is
difficult given that you would normally do something as simple as this
without resorting to code i.e. you would simply look at d5 and delete
manually if required. However, this does what you want


Sub Stance()
If Cells(5, 4).Value = "SB" Then
Rows(4).EntireRow.Delete
End If
End Sub

Mike

"Novice Lee" wrote:

> What I am trying to do is, check if Row 5, Column D has "SB" in the cell. If
> there is a "SB" in the cell, delete the row above it. I have done a search on
> deleting row most of the posting were for deleting blank lines and the such
> so they weren't much help to me. I am still trying to learn this stuff as
> fast as I can.
>
> Thanks

 
Reply With Quote
 
GTVT06
Guest
Posts: n/a
 
      14th Aug 2008
On Aug 14, 1:45*pm, Novice Lee <Novice...@discussions.microsoft.com>
wrote:
> What I am trying to do is, check if Row 5, Column D has "SB" in the cell.If
> there is a "SB" in the cell, delete the row above it. I have done a search on
> deleting row most of the posting were for deleting blank lines and the such
> so they weren't much help to me. I am still trying to learn this stuff as
> fast as I can.
>
> Thanks


Hello, Try this:

Sub Test)
If Cells(5, "D").Value = "SB" Then Cells(5, "D").Offset(-1,
0).EntireRow.Delete
End Sub
 
Reply With Quote
 
sbitaxi@gmail.com
Guest
Posts: n/a
 
      14th Aug 2008
On Aug 14, 2:45*pm, Novice Lee <Novice...@discussions.microsoft.com>
wrote:
> What I am trying to do is, check if Row 5, Column D has "SB" in the cell.If
> there is a "SB" in the cell, delete the row above it. I have done a search on
> deleting row most of the posting were for deleting blank lines and the such
> so they weren't much help to me. I am still trying to learn this stuff as
> fast as I can.
>
> Thanks


Sub DeleteSB()
Dim MyCell As Range
Dim SBRow As Range

Set SBRow = Range("5:5")

For Each MyCell In SBRow
If MyCell.Value = "SB" Then
MyCell.Offset(-1, 0).EntireRow.Delete
End If
Next
End Sub

This will delete row 4 if Row 5 contains "SB". If you want to delete
the previous row of any range that contains "SB", simply change the
line

SetSBRow = ActiveSheet.UsedRange.Rows
 
Reply With Quote
 
Novice Lee
Guest
Posts: n/a
 
      14th Aug 2008
I guess I forgot to mention that it would check each cell in column D for a
"SB" throughout the entire sheet that sheet.

"Mike H" wrote:

> hi,,
>
> Giving an answer that you can develop into more meaaningful code is
> difficult given that you would normally do something as simple as this
> without resorting to code i.e. you would simply look at d5 and delete
> manually if required. However, this does what you want
>
>
> Sub Stance()
> If Cells(5, 4).Value = "SB" Then
> Rows(4).EntireRow.Delete
> End If
> End Sub
>
> Mike
>
> "Novice Lee" wrote:
>
> > What I am trying to do is, check if Row 5, Column D has "SB" in the cell. If
> > there is a "SB" in the cell, delete the row above it. I have done a search on
> > deleting row most of the posting were for deleting blank lines and the such
> > so they weren't much help to me. I am still trying to learn this stuff as
> > fast as I can.
> >
> > Thanks

 
Reply With Quote
 
sbitaxi@gmail.com
Guest
Posts: n/a
 
      14th Aug 2008
On Aug 14, 3:03*pm, Novice Lee <Novice...@discussions.microsoft.com>
wrote:
> I guess I forgot to mention that it would check each cell in column D fora
> "SB" throughout the entire sheet that sheet.
>
> "Mike H" wrote:
> > hi,,

>
> > Giving an answer that you can develop into more meaaningful code is
> > difficult given that you would normally do something as simple as this
> > without resorting to code i.e. you would simply look at d5 and delete
> > manually if required. However, this does what you want

>
> > Sub Stance()
> > If Cells(5, 4).Value = "SB" Then
> > Rows(4).EntireRow.Delete
> > End If
> > End Sub

>
> > Mike

>
> > "Novice Lee" wrote:

>
> > > What I am trying to do is, check if Row 5, Column D has "SB" in the cell. If
> > > there is a "SB" in the cell, delete the row above it. I have done a search on
> > > deleting row most of the posting were for deleting blank lines and the such
> > > so they weren't much help to me. I am still trying to learn this stuff as
> > > fast as I can.

>
> > > Thanks


Revision to my code

Sub DeleteSB()
Dim MyCell As Range
Dim SBRow As Range

Set SBRow = Range("D")

For Each MyCell In SBRow
If MyCell.Value = "SB" Then
MyCell.Offset(-1, 0).EntireRow.Delete
End If
Next
End Sub

This will do what you want.
 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      14th Aug 2008
sub trythis()
for i=cells(rows.count,"d").end(xlup).row to 2 step-1
if ucase(cells(i,"d"))="SB" the rows(i-1).delete
next i
end sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Novice Lee" <(E-Mail Removed)> wrote in message
news:F78DB4D6-CEB4-4022-A8E6-(E-Mail Removed)...
>I guess I forgot to mention that it would check each cell in column D for a
> "SB" throughout the entire sheet that sheet.
>
> "Mike H" wrote:
>
>> hi,,
>>
>> Giving an answer that you can develop into more meaaningful code is
>> difficult given that you would normally do something as simple as this
>> without resorting to code i.e. you would simply look at d5 and delete
>> manually if required. However, this does what you want
>>
>>
>> Sub Stance()
>> If Cells(5, 4).Value = "SB" Then
>> Rows(4).EntireRow.Delete
>> End If
>> End Sub
>>
>> Mike
>>
>> "Novice Lee" wrote:
>>
>> > What I am trying to do is, check if Row 5, Column D has "SB" in the
>> > cell. If
>> > there is a "SB" in the cell, delete the row above it. I have done a
>> > search on
>> > deleting row most of the posting were for deleting blank lines and the
>> > such
>> > so they weren't much help to me. I am still trying to learn this stuff
>> > as
>> > fast as I can.
>> >
>> > Thanks


 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      14th Aug 2008
Yes you did neglect to mention that. have a look at your other response

"Novice Lee" wrote:

> I guess I forgot to mention that it would check each cell in column D for a
> "SB" throughout the entire sheet that sheet.
>
> "Mike H" wrote:
>
> > hi,,
> >
> > Giving an answer that you can develop into more meaaningful code is
> > difficult given that you would normally do something as simple as this
> > without resorting to code i.e. you would simply look at d5 and delete
> > manually if required. However, this does what you want
> >
> >
> > Sub Stance()
> > If Cells(5, 4).Value = "SB" Then
> > Rows(4).EntireRow.Delete
> > End If
> > End Sub
> >
> > Mike
> >
> > "Novice Lee" wrote:
> >
> > > What I am trying to do is, check if Row 5, Column D has "SB" in the cell. If
> > > there is a "SB" in the cell, delete the row above it. I have done a search on
> > > deleting row most of the posting were for deleting blank lines and the such
> > > so they weren't much help to me. I am still trying to learn this stuff as
> > > fast as I can.
> > >
> > > Thanks

 
Reply With Quote
 
Novice Lee
Guest
Posts: n/a
 
      14th Aug 2008
Thanks it work perfectly

"(E-Mail Removed)" wrote:

> On Aug 14, 3:03 pm, Novice Lee <Novice...@discussions.microsoft.com>
> wrote:
> > I guess I forgot to mention that it would check each cell in column D for a
> > "SB" throughout the entire sheet that sheet.
> >
> > "Mike H" wrote:
> > > hi,,

> >
> > > Giving an answer that you can develop into more meaaningful code is
> > > difficult given that you would normally do something as simple as this
> > > without resorting to code i.e. you would simply look at d5 and delete
> > > manually if required. However, this does what you want

> >
> > > Sub Stance()
> > > If Cells(5, 4).Value = "SB" Then
> > > Rows(4).EntireRow.Delete
> > > End If
> > > End Sub

> >
> > > Mike

> >
> > > "Novice Lee" wrote:

> >
> > > > What I am trying to do is, check if Row 5, Column D has "SB" in the cell. If
> > > > there is a "SB" in the cell, delete the row above it. I have done a search on
> > > > deleting row most of the posting were for deleting blank lines and the such
> > > > so they weren't much help to me. I am still trying to learn this stuff as
> > > > fast as I can.

> >
> > > > Thanks

>
> Revision to my code
>
> Sub DeleteSB()
> Dim MyCell As Range
> Dim SBRow As Range
>
> Set SBRow = Range("D")
>
> For Each MyCell In SBRow
> If MyCell.Value = "SB" Then
> MyCell.Offset(-1, 0).EntireRow.Delete
> End If
> Next
> End Sub
>
> This will do what you want.
>

 
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
Extract data from previous week, previous two weeks, etc. Kurt Microsoft Access Queries 2 15th Sep 2010 02:00 PM
3-Color Scale Vlookup for Current Month/Previous/Pre-Previous NeoFax Microsoft Excel Misc 2 8th Jan 2010 07:04 PM
Delelting files =?Utf-8?B?TWFyayBDaGFwbWFu?= Windows XP Help 2 12th Aug 2006 03:07 AM
Delelting programmes Lynn W Windows XP Help 6 14th May 2004 06:51 PM
delelting files Tony Williams Microsoft Windows 2000 6 4th Aug 2003 11:23 PM


Features
 

Advertising
 

Newsgroups
 


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