Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete rows and columns with regard to a selectes Cell

Status
Not open for further replies.

CHTHOMAS

Programmer
Jun 16, 1999
106
AE
Hi,
i want to record a macro in Excel such that after selecting a cell, i want to run the macro which should delete all the columns after that selected cell and all the rows below the selected cell. How to do that. Any help will be appreciated.

Regards,

Charley
 
Charley,

Here's code I created and tested.

It works, but please confirm that it's what you expected.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca



Dim addr1 As String
Dim addr2 As String
Dim addr As String

Sub Delete_Rows_Columns()
Delete_Rows
Delete_Columns
End Sub

Sub Delete_Rows()
addr1 = ActiveCell.Address
ActiveCell.SpecialCells(xlLastCell).Select
addr2 = ActiveCell.Address
addr = addr1 & ":" & addr2
Range(addr).Select
Selection.EntireRow.Select
Selection.Delete
Range(addr1).Select
End Sub

Sub Delete_Columns()
addr1 = ActiveCell.Address
ActiveCell.SpecialCells(xlLastCell).Select
addr2 = ActiveCell.Address
addr = addr1 & ":" & addr2
Range(addr).Select
Selection.EntireColumn.Select
Selection.Delete
Range(addr1).Select
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top