Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default How do I select a range using a macro?

Via macro, I would like to delete all rows that have a value of one (1) in
column H. All rows that have a value of (1) will be contiguous, meaning they
will follow one after the other (they won't be separate by rows in between
that do not have a value of (1) in column H); however, where the rows with a
value of (1) begin and end will vary each time the macro is used.

For example, rows 1 through 10 will not have a value of (1) in column H, but
rows 11 through 14 will. The next time the macro is run, it may be that rows
one through eight won't have a value of (1) in column H, but rows nine
through eleven will.

I'd like the macro to identify these rows with a value of (1) in column H,
select just those rows, and delete them.

Thanks for the help!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 380
Default How do I select a range using a macro?

Public Sub test()
Dim iLastRow As Long
Dim i As Long
Dim iStart As Long
Dim iEnd As Long

With ActiveSheet

iLastRow = .Cells(.Rows.Count, "H").End(xlUp).Row
For i = 1 To iLastRow + 1
If Cells(i, "H").Value = 1 Then
iStart = i
Do
i = i + 1
Loop Until Cells(i, "H").Value < 1
iEnd = i - 1
Exit For
End If
Next i

If iStart 0 Then Rows(iStart & ":" & iEnd).Delete

End With

End Sub


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"brettopp" wrote in message
...
Via macro, I would like to delete all rows that have a value of one (1) in
column H. All rows that have a value of (1) will be contiguous, meaning

they
will follow one after the other (they won't be separate by rows in between
that do not have a value of (1) in column H); however, where the rows with

a
value of (1) begin and end will vary each time the macro is used.

For example, rows 1 through 10 will not have a value of (1) in column H,

but
rows 11 through 14 will. The next time the macro is run, it may be that

rows
one through eight won't have a value of (1) in column H, but rows nine
through eleven will.

I'd like the macro to identify these rows with a value of (1) in column H,
select just those rows, and delete them.

Thanks for the help!



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default How do I select a range using a macro?

Sub delete_some_rows()
Dim C As Range
With Columns("H")
Do
Set C = .Find(1, LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False)
If C Is Nothing Then Exit Do
C.EntireRow.Delete
Loop
End With
End Sub


Gord Dibben MS Excel MVP

On Wed, 8 Nov 2006 14:53:02 -0800, brettopp
wrote:

Via macro, I would like to delete all rows that have a value of one (1) in
column H. All rows that have a value of (1) will be contiguous, meaning they
will follow one after the other (they won't be separate by rows in between
that do not have a value of (1) in column H); however, where the rows with a
value of (1) begin and end will vary each time the macro is used.

For example, rows 1 through 10 will not have a value of (1) in column H, but
rows 11 through 14 will. The next time the macro is run, it may be that rows
one through eight won't have a value of (1) in column H, but rows nine
through eleven will.

I'd like the macro to identify these rows with a value of (1) in column H,
select just those rows, and delete them.

Thanks for the help!


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default How do I select a range using a macro?

Bob and Gord, thank you for your replies! I ended up going with Gord's
simply because the coding was shorter. It was exactly what I was looking for.

Brett


"Gord Dibben" wrote:

Sub delete_some_rows()
Dim C As Range
With Columns("H")
Do
Set C = .Find(1, LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False)
If C Is Nothing Then Exit Do
C.EntireRow.Delete
Loop
End With
End Sub


Gord Dibben MS Excel MVP

On Wed, 8 Nov 2006 14:53:02 -0800, brettopp
wrote:

Via macro, I would like to delete all rows that have a value of one (1) in
column H. All rows that have a value of (1) will be contiguous, meaning they
will follow one after the other (they won't be separate by rows in between
that do not have a value of (1) in column H); however, where the rows with a
value of (1) begin and end will vary each time the macro is used.

For example, rows 1 through 10 will not have a value of (1) in column H, but
rows 11 through 14 will. The next time the macro is run, it may be that rows
one through eight won't have a value of (1) in column H, but rows nine
through eleven will.

I'd like the macro to identify these rows with a value of (1) in column H,
select just those rows, and delete them.

Thanks for the help!



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
Macro help Joe Excel Discussion (Misc queries) 27 May 14th 06 01:20 PM
Range Name affecting speed of macro Richard Buttrey Excel Worksheet Functions 5 May 1st 06 03:06 PM
Copy/Paste using a macro that identifies occuoied range JorgeAE Setting up and Configuration of Excel 1 March 13th 06 12:51 AM
checking that cells have a value before the workbook will close kcdonaldson Excel Worksheet Functions 8 December 5th 05 04:57 PM
Match function...random search? Les Excel Worksheet Functions 10 July 28th 05 11:54 AM


All times are GMT +1. The time now is 02:06 PM.

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

About Us

"It's about Microsoft Excel"