Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
KtM KtM is offline
external usenet poster
 
Posts: 13
Default Deleting cells

Hi!
I cant seem to make a "short and reliable" worksheet modifier on excel.
Idea is to delete the entire rows if even one of the values corresponds
to N.

Example:
1a Y
1a Y
1a Y
1b Y
1b Y
1b N
1b Y

If there is even one N on the range(1a to 10a) delete all the rows
corresponding to that range.
In this example all rows under 1b would be deleted.
This will be applied to N sheets, so doing it manually(how I started)
results in very messy code and the range might change in the future to
include 11a etc.
Ideas?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting cells

A range is generally referred to as A1:A10. It is unclear in your example
what you are referring to. You using N as a value and then using N as the
number of sheets. It is unclear if your values are in a single column or
two or more columns, if 1a is a value in a cell or some designation of a
row.

Row ColA ColB
1 1a Y
2 1a Y
3 1a Y
4 1b Y
5 1b Y
6 1b N
7 1b Y

Might be what your describing, with "1a" (a value in cell A1 for example)
being some code that represents a group and "1b" representing a second
group. Then if any group has a "N" value in column B, then all the rows of
the group should be deleted.

Is that what you are trying to say? If not, then what.

--
Regards,
Tom Ogilvy


"KtM" wrote in message
ps.com...
Hi!
I cant seem to make a "short and reliable" worksheet modifier on excel.
Idea is to delete the entire rows if even one of the values corresponds
to N.

Example:
1a Y
1a Y
1a Y
1b Y
1b Y
1b N
1b Y

If there is even one N on the range(1a to 10a) delete all the rows
corresponding to that range.
In this example all rows under 1b would be deleted.
This will be applied to N sheets, so doing it manually(how I started)
results in very messy code and the range might change in the future to
include 11a etc.
Ideas?



  #3   Report Post  
Posted to microsoft.public.excel.programming
KtM KtM is offline
external usenet poster
 
Posts: 13
Default Deleting cells

Sorry, should have used a bit more variables and such.

You are correct on the way you put them colA has the items(ranged from
1 to 10 with varying numbers of subcategories(a,b,c,d...) and they are
logically ordered. Actually there is a 3rd column related to this, but
it is not required for this(with the number of degree attained). So,
basically I need to find first N on each subcategory and delete
everything including the line with first N(o) from that subcategory and
forward. In the example deleting lines 6 and 7(and more if theres more
on the 1b).

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting cells

Sub DeleteRows()
Dim sh As Worksheet
Dim lastrow As Long, i As Long, j As Long
For Each sh In Workhsheets
sh.Activate
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 1 Step -1
If Cells(i, "B") = "N" Then
j = i
Do While Cells(j, "A") = Cells(i, "A")
j = j + 1
Loop
Range(Cells(i, 1), Cells(j - 1, 1)) _
.EntireRow.Delete
End If
Next i
Next sh
End Sub

--
Regards,
Tom Ogilvy





"KtM" wrote in message
oups.com...
Sorry, should have used a bit more variables and such.

You are correct on the way you put them colA has the items(ranged from
1 to 10 with varying numbers of subcategories(a,b,c,d...) and they are
logically ordered. Actually there is a 3rd column related to this, but
it is not required for this(with the number of degree attained). So,
basically I need to find first N on each subcategory and delete
everything including the line with first N(o) from that subcategory and
forward. In the example deleting lines 6 and 7(and more if theres more
on the 1b).



  #5   Report Post  
Posted to microsoft.public.excel.programming
KtM KtM is offline
external usenet poster
 
Posts: 13
Default Deleting cells

Thanks, it works nicely after a few modifications(just changed it so it
runs once/each sheet read in)
Btw, if you change the For each sh in worksheets to a counter For Ndx
to X
It produces a nice error I have never seen with XL before :)
(X is some pretermined maximum, like number of sheets etc)

One weird thing is that it only works on certain sheets, but doesnt
touch other sheets read in, all have similar formatting and "same" data
in.

Thank you once again and Happy Holidays.



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
Deleting Cells or Rows of Cells Nelly Excel Discussion (Misc queries) 3 August 22nd 07 11:46 AM
deleting unused cells / getting rid of inactive cells Woody13 Excel Discussion (Misc queries) 3 January 26th 06 09:11 PM
Deleting Cells Bill[_30_] Excel Programming 2 September 8th 05 06:31 PM
Deleting #N/A from cells... Jambruins Excel Discussion (Misc queries) 3 February 22nd 05 11:36 PM
Deleting Hyphens or Dashes from multiple cells without deleting the remaining content rmaloy Excel Programming 5 February 9th 04 01:59 AM


All times are GMT +1. The time now is 12:25 PM.

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"