Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Deleting groups of continuous rows where col K = "x"

Hi guys,

I want to delete groups of 9 continuous rows from where a flag: "X" is found
in col K. Eg: if K10 contains: "X", delete entire rows 10-18, and if K100
contains: "X", delete entire rows 100-108, and so on. Thanks.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Deleting groups of continuous rows where col K = "x"

Hi Max,

Try:

'================
Public Sub DeleteFlag()
Dim rng As range
Dim rCell As range
Dim delRng As range
Dim WB As Workbook
Dim SH As Worksheet
Dim CalcMode As Long
Dim ViewMode As Long
Const Flag As String = "Max" '<<===== CHANGE

Set WB = ActiveWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE

Set rng = Intersect(SH.UsedRange, SH.Columns("K:K"))

On Error GoTo XIT

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveWindow
ViewMode = .View
.View = xlNormalView
End With

SH.DisplayPageBreaks = False


For Each rCell In rng.Cells
With rCell
If InStr(1, .Value, Flag, vbTextCompare) Then
If delRng Is Nothing Then
Set delRng = .resize(9)
Else
Set delRng = Union(.resize(9), delRng)
End If
End If
End With
Next rCell

If Not delRng Is Nothing Then
delRng.EntireRow.Delete
Else
'nothing found, do nothing
End If

XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

ActiveWindow.View = ViewMode

End Sub
'<<================


---
Regards,
Norman



"Max" wrote in message
...
Hi guys,

I want to delete groups of 9 continuous rows from where a flag: "X" is
found
in col K. Eg: if K10 contains: "X", delete entire rows 10-18, and if K100
contains: "X", delete entire rows 100-108, and so on. Thanks.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---




  #3   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Deleting groups of continuous rows where col K = "x"

Magical, Norman. Thanks !
Runs great.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---
"Norman Jones" wrote in message
...
Hi Max,

Try:

'================
Public Sub DeleteFlag()
Dim rng As range
Dim rCell As range
Dim delRng As range
Dim WB As Workbook
Dim SH As Worksheet
Dim CalcMode As Long
Dim ViewMode As Long
Const Flag As String = "Max" '<<===== CHANGE

Set WB = ActiveWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE

Set rng = Intersect(SH.UsedRange, SH.Columns("K:K"))

On Error GoTo XIT

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveWindow
ViewMode = .View
.View = xlNormalView
End With

SH.DisplayPageBreaks = False


For Each rCell In rng.Cells
With rCell
If InStr(1, .Value, Flag, vbTextCompare) Then
If delRng Is Nothing Then
Set delRng = .resize(9)
Else
Set delRng = Union(.resize(9), delRng)
End If
End If
End With
Next rCell

If Not delRng Is Nothing Then
delRng.EntireRow.Delete
Else
'nothing found, do nothing
End If

XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

ActiveWindow.View = ViewMode

End Sub
'<<================


---
Regards,
Norman



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Deleting groups of continuous rows where col K = "x"

Hi Max,

"She Wore a Yellow Ribbon" is on TV now, but I managed to get
this put together...
If it doesn't work blame it on John Wayne.<g
Regards,
Jim Cone
San Francisco, USA
'-------------------------
Sub GetThemXRows()
Dim rngStart As Excel.Range
Dim lngRow As Long
Set rngStart = _
Application.Intersect(ActiveSheet.UsedRange, ActiveSheet.Columns("K")).Cells
For lngRow = rngStart.Rows.Count To 1 Step -1
If rngStart(lngRow).Value = "X" Then
rngStart(lngRow).Resize(9, 1).EntireRow.Delete
End If
Next ' lngRow
Set rngStart = Nothing
End Sub
'------------------------------


"Max" wrote in message...
Hi guys,

I want to delete groups of 9 continuous rows from where a flag: "X" is found
in col K. Eg: if K10 contains: "X", delete entire rows 10-18, and if K100
contains: "X", delete entire rows 100-108, and so on. Thanks.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---


  #5   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Deleting groups of continuous rows where col K = "x"

Jim, thanks for the artillery. I'm pretty sure it's not because of John
Wayne, but I could not get the cannons to fire, despite several tries. My
attempts fizzled out dismally (nothing happened on the sheet). What can I do
to feel the power ?
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---
"Jim Cone" wrote in message
...
Hi Max,

"She Wore a Yellow Ribbon" is on TV now, but I managed to get
this put together...
If it doesn't work blame it on John Wayne.<g
Regards,
Jim Cone
San Francisco, USA
'-------------------------
Sub GetThemXRows()
Dim rngStart As Excel.Range
Dim lngRow As Long
Set rngStart = _
Application.Intersect(ActiveSheet.UsedRange,

ActiveSheet.Columns("K")).Cells
For lngRow = rngStart.Rows.Count To 1 Step -1
If rngStart(lngRow).Value = "X" Then
rngStart(lngRow).Resize(9, 1).EntireRow.Delete
End If
Next ' lngRow
Set rngStart = Nothing
End Sub
'------------------------------





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Deleting groups of continuous rows where col K = "x"

Max,
Well is was probably Joanne Dru's fault then. <g
Norman's approach using Instr is probably what's needed.
My code only works if "X" is the only thing in the cell.
Regards,
Jim Cone
http://www.realezsites.com/bus/primitivesoftware


"Max" wrote in message...
Hi guys,
I want to delete groups of 9 continuous rows from where a flag: "X" is found
in col K. Eg: if K10 contains: "X", delete entire rows 10-18, and if K100
contains: "X", delete entire rows 100-108, and so on. Thanks.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---


  #7   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Deleting groups of continuous rows where col K = "x"

Jim, thanks for explaining the subtleties. It was the "case" of the letter
(the flag in col K). My keyboard (or my fingers, rather) weren't working
too well. When I tried it again with a true-blue upper case: "X" in col K,
your sub ran superb and beautiful, just like Joanne Dru in the movie <g.
Thanks!
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---
"Jim Cone" wrote in message
...
Max,
Well is was probably Joanne Dru's fault then. <g
Norman's approach using Instr is probably what's needed.
My code only works if "X" is the only thing in the cell.
Regards,
Jim Cone
http://www.realezsites.com/bus/primitivesoftware


"Max" wrote in message...
Hi guys,
I want to delete groups of 9 continuous rows from where a flag: "X" is

found
in col K. Eg: if K10 contains: "X", delete entire rows 10-18, and if K100
contains: "X", delete entire rows 100-108, and so on. Thanks.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---




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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Quickly moving rows of 5-column groups on 1 continuous line C.O. Excel Worksheet Functions 2 December 7th 06 09:59 PM
Shading alternate "groups" of rows? Lee Harris Excel Worksheet Functions 6 September 17th 06 03:43 PM
Deleting "duplicate" rows mmednick Excel Discussion (Misc queries) 7 January 11th 06 08:22 PM
Deleting Rows with Sum of "0" in 4 columns mike meyer Excel Programming 7 September 12th 05 06:26 PM


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