LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default deleting wrong range!

This looks funny to me:

Set rng = wsquote.Range("foldunit2")
x = rng.Rows.Count
rng.Range("foldunit2").ClearContents

maybe
wsquote.range("foldunit2").clearcontents
or just
rng.clearcontents

is what you want.

=====
Try this on a new workbook/worksheet:

Option Explicit
Sub testme01()

Dim wsQuote As Worksheet
Dim rng As Range

Set wsQuote = Worksheets("sheet2")

With wsQuote
.Range("b1").Name = "foldunit2"
Set rng = .Range("foldunit2")
End With
MsgBox rng.Address & vbLf & rng.Range("Foldunit2").Address

End Sub

In my example, FoldUnit2 refers to B1. But when I use:
rng.range("foldunit2"), it's like writing:
rng.range("b1")
which means start in B1 and go down one row and to the right one column.

msgbox range("a1").range("b1").range("c1").range("d1").ad dress

will work, but may not be what you really mean!

======
if that didn't work for you, then I'd try stepping through the code with a minor
change:

Change this line:
rng.Offset(0, 0).Resize(x).EntireRow.Delete
to this pair of lines

rng.parent.select
rng.offset(0,0).resize(x).entirerow.select

======
and rng.offset(0,0) is the same as rng.
and rng.resize(rng.rows.count)
is the same as rng
(when x = rng.rows.count)

why not:
rng.entirerow.delete
?




"gavmer <" wrote:

Sorry all, here is the code or i can e-mail a workbook??

Private Sub CommandButton1_Click()
Dim rng As Range, x As Single
Dim wsquote As Worksheet
Set wsquote = Worksheets("sheet2")
Set rng = wsquote.Range("foldunit2")
x = rng.Rows.Count
rng.Range("foldunit2").ClearContents
rng.Offset(0, 0).Resize(x).EntireRow.Delete
'Sheets("sheet 1").Range("range").ClearContents
End Sub

Private Sub CommandButton2_Click()
Dim rng As Range, x As Single
Dim wsquote As Worksheet
Set wsquote = Worksheets("sheet2")
Set rng = wsquote.Range("knifeunit2")
x = rng.Rows.Count
rng.Range("knifeunit2").ClearContents
rng.Offset(0, 0).Resize(x).EntireRow.Delete
'Sheets("sheet 1").Range("range").ClearContents
End Sub
Private Sub CommandButton3_Click()
Dim rng As Range, x As Single
Dim wsquote As Worksheet
Set wsquote = Worksheets("sheet2")
Set rng = wsquote.Range("knifeunit3")
x = rng.Rows.Count
rng.Range("knifeunit3").ClearContents
rng.Offset(0, 0).Resize(x).EntireRow.Delete
'Sheets("sheet 1").Range("range").ClearContents
End Sub

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

 
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 rows - syntax wrong? seed Excel Discussion (Misc queries) 4 March 3rd 09 07:57 PM
histogram, wrong input range Camilla Excel Discussion (Misc queries) 1 November 11th 05 07:21 AM
Deleting Range name's listed in the range address box. Satnam Patel Excel Discussion (Misc queries) 4 May 5th 05 01:42 PM
Macro selecting wrong cell range Josh[_10_] Excel Programming 1 June 23rd 04 06:48 PM
Combo Box wrong lookup range. Pal Excel Programming 2 February 28th 04 08:04 PM


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