View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Delete Function:

Watch out for what I wrote. I didn't notice that the data was on two different
rows.

You'll want to change that .offset() to come down and move to the right.

Ardy wrote:

Thank You So much it is putting it to perspective a bit........;)
Ardy
Dave Peterson wrote:
rResult is a variable that holds a reference to that range.

rResult is an object that has lots of properties. It's more complex than say a
variable declared as a Long (just a whole number).

You can get to the value.

If rResult is a single cell:
Msgbox rResult.value
or its address:
msgbox rResult.address
or lots more things

Put your cursor on "Range" in this line"
Dim rResult as Range
and hit F1 and you'll be taken to VBA's help for Range objects.

rResult(1) will refer to the first cell in that range. The user can select lots
of cells. JE wants to just use the first in his code.

And one of the properties that a range has is .Offset() and another is
.Resize().

rResult(1).offset(0,1)
will stay on the same row (0) and go one column to the right.

rResult(1).offset(0,1).resize(1,59)
will "move" one cell to the right and resize that range to 1 row by 59 columns

So
rResult(1).offset(0,1).resize(1,59).clearcontents
or avoiding the offset()
rResult(1).resize(1,60).clearcontents

(I think that A:BH is 60 columns--check my work before you trust it!)

Ardy wrote:

Great it works and no error on cancel.
I have two questions and a request.
Q1. Dose the variable rResult holds the cell number or content? i.e
A3(#A#3) or the content "Some Text"
Q2. Explain the (1) after rResult. What function dose it serves what
is it doing

Request: Assuming that the cell we are clearing the content
(rResult(1).ClearContents) has more information in front of it C3:BH3
how would one clear those. The confusing part for me is how to capture
the initial cell id and make the related range to clear.
Example:
The user picks Cell A2 that has the content "Some Text" the current
code dose perfect it clears it and deletes the tab that has the "Some
Text". Now visualize there are more related information in cell C3:BH3
that also needs to be cleared.

Ardy

Dave Peterson wrote:
How about this minor modification to JE's code:

Dim rResult As Range
Do
on error resume next
Set rResult = Application.InputBox( _
Prompt:="Select cell to clear: ", _
Title:="Clear cell and delete sheet", _
Type:=8)
on error goto 0
If rResult Is Nothing Then Exit Sub 'User cancelled
Loop Until Not Intersect(rResult(1), Range("A2:A100")) Is Nothing
On Error Resume Next
Application.DisplayAlerts = False
Sheets(rResult(1).Text).Delete
Application.DisplayAlerts = True
On Error GoTo 0
rResult(1).ClearContents

Ardy wrote:

JE.
I also get a Run Time Error"424', Object Required when pressing cancel.
Ardy
Ardy wrote:
This is great this works pritty good, I got to modify the message and
all and all couple of other things to it to make it fit the situation,
One thing is that how would you expand on this code and capture the
content and use it to delete the respected tab which has the same name
as the cell content that we are just abt to delete.

Ardy
JE McGimpsey wrote:
One way:

Dim rResult As Range
Do
Set rResult = Application.InputBox( _
Prompt:="Select cell to clear: ", _
Title:="Clear cell and delete sheet", _
Type:=8)
If rResult Is Nothing Then Exit Sub 'User cancelled
Loop Until Not Intersect(rResult(1), Range("A2:A100")) Is Nothing
On Error Resume Next
Application.DisplayAlerts = False
Sheets(rResult(1).Text).Delete
Application.DisplayAlerts = True
On Error GoTo 0
rResult(1).ClearContents


In article . com,
"Ardy" wrote:

I am trying to create a macro that will delete a cell content and
related tab by picking the cell. i.e. We have bunch of names in column
A starting at A2 in tab "Roster". Each name in "Roster" has
its own respected Tab. The macro or Code once activated will have the
user to pick the cell that has the name to be deleted, clears the
content, but before clearing will capture the name in a variable that
will be used to find the respected tab and delete the tab as well.
Any help on this is appreciated.

Ardy

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson