Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Macro definition help

Sub DeleteHeadings()
Dim rng As Range
Dim target As String
target = InputBox("Enter Search Term")
If target = "" Then Exit Sub
Do
If Not rng Is Nothing Then
rng.Resize(8, 1).EntireRow.Delete
End If
Set rng = Nothing
Set rng = Cells.Find(What:=target, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
Loop While Not rng Is Nothing
End Sub

Can someone explain me in simple words what is this macro performing step by
step. I would really appreciate that. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Macro definition help

I can try.

Dim rng as Range
declares a variable that may refer to a cell, or group of cells or other
Excel "Range"
Dim target As String
declares a variable that may contain a text value

target = InputBox("Enter Search Term")
requesting you provide a term/phrase/value you want to search for later

If target="" Then Exit Sub
if you didn't enter anything for a search term in the InputBox statement,
then get out.

the
Do
....
Loop While Not rng Is Nothing

Is Nothing is a condition examining the variable rng and asking "did this
get assigned to some real world range in my workbook). If rng does not refer
to anything, it will be "Is Nothing", so Not ... Is Nothing is saying "do
this while rng is referring to some real-world range".

Inside of the loop, rng actually starts off as Is Nothing so that
If Not rng Is Nothing Then
rng.Resize(8,1).EntireRow.Delete
End if
never gets executed the first time thru the loop, but then is continually
executed until there is no match found for the phrase entered earlier. But
when rng does refer to (a cell) the .Resize(8,1) then makes it refer to that
cell and the 7 cells below it, then by referring to .EntireRow it is now
referring to the row the match was found in along with the next 7 rows, and
the .Delete does exactly that: deletes the 8 rows!

Set rng = Nothing
sets rng back to nothingness so that if no match is found in the next
statement, the loop will end.

The next statement is a simple .Find command that looks for the phrase you
entered. If it is found, then rng will be set to the cell/range where it was
found, and the loop will continue and that cell/range and the 7 rows below it
will be deleted.

Repeat until no more matches are found.




"andresg1975" wrote:

Sub DeleteHeadings()
Dim rng As Range
Dim target As String
target = InputBox("Enter Search Term")
If target = "" Then Exit Sub
Do
If Not rng Is Nothing Then
rng.Resize(8, 1).EntireRow.Delete
End If
Set rng = Nothing
Set rng = Cells.Find(What:=target, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
Loop While Not rng Is Nothing
End Sub

Can someone explain me in simple words what is this macro performing step by
step. I would really appreciate that. Thanks.

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
name definition x taol Excel Programming 2 November 23rd 06 11:52 AM
Macro to Uncheck Save Query Definition NYbills Excel Programming 1 July 28th 06 06:51 PM
Range Definition in Macro ? Baapi Excel Programming 1 September 23rd 05 12:08 AM
Syntax problem in defining OnAction macro definition held in Add-in! Charles Jordan Excel Programming 4 March 5th 05 06:35 AM
Remove Query Definition with Macro or VBA Paul Simpson Excel Programming 2 January 6th 05 11:20 AM


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