LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Delete last row from range

Hi,

I have code as follows,

Dim DataRow As Long
Application.ScreenUpdating = False
DataRow = ProjectsListBox.ListIndex + 1
With ThisWorkbook.Worksheets("Data")
Rng.Rows(DataRow).Delete xlShiftUp
' If listbox entries have all been deleted, reset the 'Rng'
object _
' so that a valid rowsource can be updated.
If Rng Is Nothing Then
Set Rng = .Range("S2").Resize(, 2)
Else
Set Rng = .Range("S2").Resize(Rng.Rows.Count, 2)
End If
ProjectsListBox.RowSource = Rng.Address(External:=True)
ProjectsListBox.ListIndex = -1
End With

My problem is with my set 'Rng'. If the last row of the range object
'Rng'
is deleted, "Rng Is Nothing" always returns false and then errors. Rng
is
initially set to a worksheet range and works well until the last entry
is deleted.
Any suggestions or alternatives?

Regards,

Stefano

 
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
delete range using VBA Wanna Learn Excel Discussion (Misc queries) 2 May 7th 23 11:45 AM
How to Delete blanks between a range and populate only the names inthe given range Yuvraj Excel Discussion (Misc queries) 2 November 4th 09 08:32 PM
How to Delete a Range in Closed Workbook (to Replace Delete Query) [email protected] Excel Discussion (Misc queries) 1 March 8th 06 10:10 AM
Range.Delete and Range.Resize.Name performance issues Test.File Excel Programming 0 February 15th 05 03:33 PM
Delete range gavmer[_42_] Excel Programming 1 June 30th 04 07:24 AM


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