ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete range (https://www.excelbanter.com/excel-programming/302969-delete-range.html)

gavmer[_42_]

Delete range
 
Hi all,

Im having a problem with code deleting more than it should. With th
code below, i am running it multiple times with different buttons
Problem is, it tends to delete other data on occassions that is no
part of the range. I dont know why. The data it deletes is data paste
from another sheet where the code works ok? Does this mean anything? I
it the code???

Any ideas????

Cheers!!

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


gavmer[_43_]

Delete range
 
sorry, here is the code:

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

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

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

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



All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com