Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default MACRO TO DELET ROWS DEPENDING ON CELL VALUES

hi, I have data in range (A1:C1000) and this range can increase or
decrease depending on the data I receive and remove. See the little
version of data below that I have

ROW A B C -----col
1 GG ZZZ -100
2 GG BBB 200
3 SS HHH 300
4 TT XXX -600
5 VV GGG 200
6 XX TTT 900
7 GG UUU 700
8 YY AAA 400
9 TT XXX 600
10 VV GGG -200
11 ZZ FFF 600
12 GG ZZZ 100

I want macro which should check in whole column A and B cells that if
the same codes value in these columns have + and - figures in column C
cells then it should delete both those rows. For example as in above
data in row 1 I have code GG in cell A1 and code ZZZ in cell B1 then
macro should find both these codes in whole column A and B and see how
many times these both codes appearing in same row and if they have +
and - figures in column C in same row cell then both rows of those +
and - figures should be deleted. Note that the GG and ZZZ codes can
be appear ten times in column A & B and so macro should check all and
so on with other codes. Please if any friend can help me in this
matter. if someone can come up with small macro which can do this job
then it will much helpful but otherwise any macro will do.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default MACRO TO DELET ROWS DEPENDING ON CELL VALUES

Try this on a copy of your sheet first. It workded on my sample but you need
to test it before permanent installation.


Sub delZero()
Dim fRng As Range, LastCell As Range
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lastRow To 2 Step -1
Set fRng = ActiveSheet.Range("A1:A" & Cells(i, 1).Row - 1) _
.Find(Cells(i, 1).Value, LookIn:=xlValues)
If Not fRng Is Nothing Then
For j = 1 To Cells(i, 1).Row
If ActiveSheet.Cells(i, 1).Value = fRng.Value And _
ActiveSheet.Cells(i, 2).Value = fRng.Offset(0, 1).Value _
And ActiveSheet.Cells(i, 3).Value + fRng.Offset(0, 2).Value = 0 Then
Cells(i, 1).EntireRow.Delete
fRng.EntireRow.Delete
Exit For
End If
Next
End If
Next
End Sub

"K" wrote:

hi, I have data in range (A1:C1000) and this range can increase or
decrease depending on the data I receive and remove. See the little
version of data below that I have

ROW A B C -----col
1 GG ZZZ -100
2 GG BBB 200
3 SS HHH 300
4 TT XXX -600
5 VV GGG 200
6 XX TTT 900
7 GG UUU 700
8 YY AAA 400
9 TT XXX 600
10 VV GGG -200
11 ZZ FFF 600
12 GG ZZZ 100

I want macro which should check in whole column A and B cells that if
the same codes value in these columns have + and - figures in column C
cells then it should delete both those rows. For example as in above
data in row 1 I have code GG in cell A1 and code ZZZ in cell B1 then
macro should find both these codes in whole column A and B and see how
many times these both codes appearing in same row and if they have +
and - figures in column C in same row cell then both rows of those +
and - figures should be deleted. Note that the GG and ZZZ codes can
be appear ten times in column A & B and so macro should check all and
so on with other codes. Please if any friend can help me in this
matter. if someone can come up with small macro which can do this job
then it will much helpful but otherwise any macro will do.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default MACRO TO DELET ROWS DEPENDING ON CELL VALUES

If you have a header row, this will probably work better.

Sub delZero()
Dim fRng As Range, LastCell As Range
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lastRow To 2 Step -1
Set fRng = ActiveSheet.Range("A2:A" & Cells(i, 1).Row - 1) _
.Find(Cells(i, 1).Value, After:=Cells(i - 1, 1), LookIn:=xlValues)
If Not fRng Is Nothing Then
For j = 1 To Cells(i, 1).Row
If ActiveSheet.Cells(i, 1).Value = fRng.Value And _
ActiveSheet.Cells(i, 2).Value = fRng.Offset(0, 1).Value _
And ActiveSheet.Cells(i, 3).Value + fRng.Offset(0, 2).Value = 0 Then
Cells(i, 1).EntireRow.Delete
fRng.EntireRow.Delete
Exit For
End If
Next
End If
Next
End Sub

"K" wrote:

hi, I have data in range (A1:C1000) and this range can increase or
decrease depending on the data I receive and remove. See the little
version of data below that I have

ROW A B C -----col
1 GG ZZZ -100
2 GG BBB 200
3 SS HHH 300
4 TT XXX -600
5 VV GGG 200
6 XX TTT 900
7 GG UUU 700
8 YY AAA 400
9 TT XXX 600
10 VV GGG -200
11 ZZ FFF 600
12 GG ZZZ 100

I want macro which should check in whole column A and B cells that if
the same codes value in these columns have + and - figures in column C
cells then it should delete both those rows. For example as in above
data in row 1 I have code GG in cell A1 and code ZZZ in cell B1 then
macro should find both these codes in whole column A and B and see how
many times these both codes appearing in same row and if they have +
and - figures in column C in same row cell then both rows of those +
and - figures should be deleted. Note that the GG and ZZZ codes can
be appear ten times in column A & B and so macro should check all and
so on with other codes. Please if any friend can help me in this
matter. if someone can come up with small macro which can do this job
then it will much helpful but otherwise any macro will do.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default MACRO TO DELET ROWS DEPENDING ON CELL VALUES

On 26 Apr, 04:25, JLGWhiz wrote:
If you have a header row, this will probably work better.

Sub delZero()
* Dim fRng As Range, LastCell As Range
* lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
* For i = lastRow To 2 Step -1
* * *Set fRng = ActiveSheet.Range("A2:A" & Cells(i, 1).Row - 1) _
* * *.Find(Cells(i, 1).Value, After:=Cells(i - 1, 1), LookIn:=xlValues)
* * *If Not fRng Is Nothing Then
* * *For j = 1 To Cells(i, 1).Row
* * *If ActiveSheet.Cells(i, 1).Value = fRng.Value And _
* * *ActiveSheet.Cells(i, 2).Value = fRng.Offset(0, 1).Value _
* * *And ActiveSheet.Cells(i, 3).Value + fRng.Offset(0, 2).Value = 0 Then
* * * *Cells(i, 1).EntireRow.Delete
* * * *fRng.EntireRow.Delete
* * * *Exit For
* * *End If
* * *Next
* * *End If
* Next
End Sub



"K" wrote:
hi, I have data in range (A1:C1000) and this range can increase or
decrease depending on the data I receive and remove. See the little
version of data below that I have


ROW * * *A * * * * * *B * * * * *C -----col
1 * * * * * GG * * * *ZZZ * * *-100
2 * * * * * GG * * * BBB * * * 200
3 * * * * * SS * * * *HHH * * *300
4 * * * * * *TT * * * *XXX * * * -600
5 * * * * * *VV * * *GGG * * * 200
6 * * * * * *XX * * * TTT * * * * 900
7 * * * * * *GG * * *UUU * * * 700
8 * * * * * *YY * * *AAA * * * *400
9 * * * * * * TT * * *XXX * * * * 600
10 * * * * * VV * * GGG * * *-200
11 * * * * * ZZ * * *FFF * * * * 600
12 * * * * * GG * * *ZZZ * * * *100


I want macro which should check in whole column A and B cells that if
the same codes value in these columns have + and - figures in column C
cells then it should delete both those rows. *For example as in above
data in row 1 I have code GG in cell A1 and code ZZZ in cell B1 then
macro should find both these codes in whole column A and B and see how
many times these both codes appearing in same row and if they have +
and - figures in column C in same row cell then both rows of those +
and - figures should be deleted. *Note that the GG and ZZZ codes can
be appear ten times in column A & B and so macro should check all and
so on with other codes. *Please if any friend can help me in this
matter. *if someone can come up with small macro which can do this job
then it will much helpful but otherwise any macro will do.- Hide quoted text -


- Show quoted text -


Hi JLGWhiz, Thanks for replying. i did tried your code but for some
reason its not deleting all the dr and cr figures rows. for instance
if you put the exact data the one i showed in my question into your
sheet and then run your macro then you'll see that it deletes few dr
and cr figures but leave few as well. i can send you my excel sheet
if you want me too so it can expalin you more clearly what i am tring
to do.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default MACRO TO DELET ROWS DEPENDING ON CELL VALUES

It could be that you have some extra spaces entered in some of the cells.
Try this version which trims out the extra spaces and see if it works better.

Sub delZero()
Dim fRng As Range, LastCell As Range
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lastRow To 2 Step -1
Set fRng = ActiveSheet.Range("A2:A" & Cells(i, 1).Row - 1) _
.Find(Cells(i, 1).Value, After:=Cells(i - 1, 1), LookIn:=xlValues)
If Not fRng Is Nothing Then
For j = 1 To Cells(i, 1).Row
If Trim(ActiveSheet.Cells(i, 1).Value) = Trim(fRng.Value) And _
Trim(ActiveSheet.Cells(i, 2).Value) = Trim(fRng.Offset(0, 1).Value) _
And ActiveSheet.Cells(i, 3).Value + fRng.Offset(0, 2).Value = 0 Then
Cells(i, 1).EntireRow.Delete
fRng.EntireRow.Delete
Exit For
End If
Next
End If
Next
End Sub

Another thing to check is to make sure all of your DR and CR entries are
numeric.
If they are, they should align to the right of the column.
"K" wrote:

On 26 Apr, 04:25, JLGWhiz wrote:
If you have a header row, this will probably work better.

Sub delZero()
Dim fRng As Range, LastCell As Range
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lastRow To 2 Step -1
Set fRng = ActiveSheet.Range("A2:A" & Cells(i, 1).Row - 1) _
.Find(Cells(i, 1).Value, After:=Cells(i - 1, 1), LookIn:=xlValues)
If Not fRng Is Nothing Then
For j = 1 To Cells(i, 1).Row
If ActiveSheet.Cells(i, 1).Value = fRng.Value And _
ActiveSheet.Cells(i, 2).Value = fRng.Offset(0, 1).Value _
And ActiveSheet.Cells(i, 3).Value + fRng.Offset(0, 2).Value = 0 Then
Cells(i, 1).EntireRow.Delete
fRng.EntireRow.Delete
Exit For
End If
Next
End If
Next
End Sub



"K" wrote:
hi, I have data in range (A1:C1000) and this range can increase or
decrease depending on the data I receive and remove. See the little
version of data below that I have


ROW A B C -----col
1 GG ZZZ -100
2 GG BBB 200
3 SS HHH 300
4 TT XXX -600
5 VV GGG 200
6 XX TTT 900
7 GG UUU 700
8 YY AAA 400
9 TT XXX 600
10 VV GGG -200
11 ZZ FFF 600
12 GG ZZZ 100


I want macro which should check in whole column A and B cells that if
the same codes value in these columns have + and - figures in column C
cells then it should delete both those rows. For example as in above
data in row 1 I have code GG in cell A1 and code ZZZ in cell B1 then
macro should find both these codes in whole column A and B and see how
many times these both codes appearing in same row and if they have +
and - figures in column C in same row cell then both rows of those +
and - figures should be deleted. Note that the GG and ZZZ codes can
be appear ten times in column A & B and so macro should check all and
so on with other codes. Please if any friend can help me in this
matter. if someone can come up with small macro which can do this job
then it will much helpful but otherwise any macro will do.- Hide quoted text -


- Show quoted text -


Hi JLGWhiz, Thanks for replying. i did tried your code but for some
reason its not deleting all the dr and cr figures rows. for instance
if you put the exact data the one i showed in my question into your
sheet and then run your macro then you'll see that it deletes few dr
and cr figures but leave few as well. i can send you my excel sheet
if you want me too so it can expalin you more clearly what i am tring
to do.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default MACRO TO DELET ROWS DEPENDING ON CELL VALUES

On 26 Apr, 15:54, JLGWhiz wrote:
It could be that you have some extra spaces entered in some of the cells. *
Try this version which trims out the extra spaces and see if it works better.

Sub delZero()
* Dim fRng As Range, LastCell As Range
* lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
* For i = lastRow To 2 Step -1
* * *Set fRng = ActiveSheet.Range("A2:A" & Cells(i, 1).Row - 1) _
* * *.Find(Cells(i, 1).Value, After:=Cells(i - 1, 1), LookIn:=xlValues)
* * *If Not fRng Is Nothing Then * *
* * *For j = 1 To Cells(i, 1).Row
* * *If Trim(ActiveSheet.Cells(i, 1).Value) = Trim(fRng.Value) And _
* * *Trim(ActiveSheet.Cells(i, 2).Value) = Trim(fRng.Offset(0, 1).Value) _
* * *And ActiveSheet.Cells(i, 3).Value + fRng.Offset(0, 2).Value = 0 Then
* * * *Cells(i, 1).EntireRow.Delete
* * * *fRng.EntireRow.Delete
* * * *Exit For
* * *End If
* * *Next
* * *End If
* Next
End Sub

Another thing to check is to make sure all of your DR and CR entries are
numeric.
If they are, they should align to the right of the column.



"K" wrote:
On 26 Apr, 04:25, JLGWhiz wrote:
If you have a header row, this will probably work better.


Sub delZero()
* Dim fRng As Range, LastCell As Range
* lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
* For i = lastRow To 2 Step -1
* * *Set fRng = ActiveSheet.Range("A2:A" & Cells(i, 1).Row - 1) _
* * *.Find(Cells(i, 1).Value, After:=Cells(i - 1, 1), LookIn:=xlValues)
* * *If Not fRng Is Nothing Then
* * *For j = 1 To Cells(i, 1).Row
* * *If ActiveSheet.Cells(i, 1).Value = fRng.Value And _
* * *ActiveSheet.Cells(i, 2).Value = fRng.Offset(0, 1).Value _
* * *And ActiveSheet.Cells(i, 3).Value + fRng.Offset(0, 2).Value = 0 Then
* * * *Cells(i, 1).EntireRow.Delete
* * * *fRng.EntireRow.Delete
* * * *Exit For
* * *End If
* * *Next
* * *End If
* Next
End Sub


"K" wrote:
hi, I have data in range (A1:C1000) and this range can increase or
decrease depending on the data I receive and remove. See the little
version of data below that I have


ROW * * *A * * * * * *B * * * * *C -----col
1 * * * * * GG * * * *ZZZ * * *-100
2 * * * * * GG * * * BBB * * * 200
3 * * * * * SS * * * *HHH * * *300
4 * * * * * *TT * * * *XXX * * * -600
5 * * * * * *VV * * *GGG * * * 200
6 * * * * * *XX * * * TTT * * * * 900
7 * * * * * *GG * * *UUU * * * 700
8 * * * * * *YY * * *AAA * * * *400
9 * * * * * * TT * * *XXX * * * * 600
10 * * * * * VV * * GGG * * *-200
11 * * * * * ZZ * * *FFF * * * * 600
12 * * * * * GG * * *ZZZ * * * *100


I want macro which should check in whole column A and B cells that if
the same codes value in these columns have + and - figures in column C
cells then it should delete both those rows. *For example as in above
data in row 1 I have code GG in cell A1 and code ZZZ in cell B1 then
macro should find both these codes in whole column A and B and see how
many times these both codes appearing in same row and if they have +
and - figures in column C in same row cell then both rows of those +
and - figures should be deleted. *Note that the GG and ZZZ codes can
be appear ten times in column A & B and so macro should check all and
so on with other codes. *Please if any friend can help me in this
matter. *if someone can come up with small macro which can do this job
then it will much helpful but otherwise any macro will do.- Hide quoted text -


- Show quoted text -


Hi JLGWhiz, Thanks for replying. i did tried your code but for some
reason its not deleting all the dr and cr figures rows. for instance
if you put the exact data the one i showed in my question into your
sheet and then run your macro then you'll see that it deletes few dr
and cr figures but leave few as well. *i can send you my excel sheet
if you want me too so it can expalin you more clearly what i am tring
to do.- Hide quoted text -


- Show quoted text -


Thanks lot JLGWhiz, your code working superb. i have tried it on a
sample sheet and it working very good. i'll go to my office on Monday
and will try this on original sheet and if i have any question then
i'll come back to you. Thanks lot again my friend.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default MACRO TO DELET ROWS DEPENDING ON CELL VALUES

On 27 Apr, 10:24, K wrote:
On 26 Apr, 15:54, JLGWhiz wrote:





It could be that you have some extra spaces entered in some of the cells.. *
Try this version which trims out the extra spaces and see if it works better.


Sub delZero()
* Dim fRng As Range, LastCell As Range
* lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
* For i = lastRow To 2 Step -1
* * *Set fRng = ActiveSheet.Range("A2:A" & Cells(i, 1).Row - 1) _
* * *.Find(Cells(i, 1).Value, After:=Cells(i - 1, 1), LookIn:=xlValues)
* * *If Not fRng Is Nothing Then * *
* * *For j = 1 To Cells(i, 1).Row
* * *If Trim(ActiveSheet.Cells(i, 1).Value) = Trim(fRng.Value) And _
* * *Trim(ActiveSheet.Cells(i, 2).Value) = Trim(fRng.Offset(0, 1).Value) _
* * *And ActiveSheet.Cells(i, 3).Value + fRng.Offset(0, 2).Value = 0 Then
* * * *Cells(i, 1).EntireRow.Delete
* * * *fRng.EntireRow.Delete
* * * *Exit For
* * *End If
* * *Next
* * *End If
* Next
End Sub


Another thing to check is to make sure all of your DR and CR entries are
numeric.
If they are, they should align to the right of the column.


"K" wrote:
On 26 Apr, 04:25, JLGWhiz wrote:
If you have a header row, this will probably work better.


Sub delZero()
* Dim fRng As Range, LastCell As Range
* lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
* For i = lastRow To 2 Step -1
* * *Set fRng = ActiveSheet.Range("A2:A" & Cells(i, 1).Row - 1) _
* * *.Find(Cells(i, 1).Value, After:=Cells(i - 1, 1), LookIn:=xlValues)
* * *If Not fRng Is Nothing Then
* * *For j = 1 To Cells(i, 1).Row
* * *If ActiveSheet.Cells(i, 1).Value = fRng.Value And _
* * *ActiveSheet.Cells(i, 2).Value = fRng.Offset(0, 1).Value _
* * *And ActiveSheet.Cells(i, 3).Value + fRng.Offset(0, 2).Value = 0 Then
* * * *Cells(i, 1).EntireRow.Delete
* * * *fRng.EntireRow.Delete
* * * *Exit For
* * *End If
* * *Next
* * *End If
* Next
End Sub


"K" wrote:
hi, I have data in range (A1:C1000) and this range can increase or
decrease depending on the data I receive and remove. See the little
version of data below that I have


ROW * * *A * * * * * *B * * * * *C -----col
1 * * * * * GG * * * *ZZZ * * *-100
2 * * * * * GG * * * BBB * * * 200
3 * * * * * SS * * * *HHH * * *300
4 * * * * * *TT * * * *XXX * * * -600
5 * * * * * *VV * * *GGG * * * 200
6 * * * * * *XX * * * TTT * * * * 900
7 * * * * * *GG * * *UUU * * * 700
8 * * * * * *YY * * *AAA * * * *400
9 * * * * * * TT * * *XXX * * * * 600
10 * * * * * VV * * GGG * * *-200
11 * * * * * ZZ * * *FFF * * * * 600
12 * * * * * GG * * *ZZZ * * * *100


I want macro which should check in whole column A and B cells that if
the same codes value in these columns have + and - figures in column C
cells then it should delete both those rows. *For example as in above
data in row 1 I have code GG in cell A1 and code ZZZ in cell B1 then
macro should find both these codes in whole column A and B and see how
many times these both codes appearing in same row and if they have +
and - figures in column C in same row cell then both rows of those +
and - figures should be deleted. *Note that the GG and ZZZ codes can
be appear ten times in column A & B and so macro should check all and
so on with other codes. *Please if any friend can help me in this
matter. *if someone can come up with small macro which can do this job
then it will much helpful but otherwise any macro will do.- Hide quoted text -


- Show quoted text -


Hi JLGWhiz, Thanks for replying. i did tried your code but for some
reason its not deleting all the dr and cr figures rows. for instance
if you put the exact data the one i showed in my question into your
sheet and then run your macro then you'll see that it deletes few dr
and cr figures but leave few as well. *i can send you my excel sheet
if you want me too so it can expalin you more clearly what i am tring
to do.- Hide quoted text -


- Show quoted text -


Thanks lot JLGWhiz, your code working superb. *i have tried it on a
sample sheet and it working very good. *i'll go to my office on Monday
and will try this on original sheet and if i have any question then
i'll come back to you. *Thanks lot again my friend.- Hide quoted text -

- Show quoted text -


Thanks man your code working superb
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
Summing values, x rows deep, depending on a criterion klm[_2_] Excel Worksheet Functions 2 August 18th 08 02:02 PM
delet rows based on cel content Ivano Excel Programming 4 May 10th 06 06:48 AM
Macro to coppy cells to certain rows depending on value in cell Esrei Excel Discussion (Misc queries) 0 December 9th 05 07:57 AM
counting rows depending on 2 selective values Acid-Sky Excel Discussion (Misc queries) 1 September 1st 05 05:45 PM
Protect Rows depending on Values in Particular Columns [email protected] Excel Programming 0 July 14th 05 01:11 PM


All times are GMT +1. The time now is 01:42 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"