Deleteing Row and Column in excel

jmaxwell

New Member
Joined
Nov 19, 2010
Messages
16
Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
My spreadsheets contain an uncertain amount of rows and columns. I need the macro code to delete all rows after the last data in column A and delete all columns after the last data in the last data in row 1. <o:p></o:p>
<o:p></o:p>
For example: <o:p></o:p>
<o:p></o:p>
Deleting Rows: If the last data in column A is "A150", then delete all rows after "A150"<o:p></o:p>
<o:p></o:p>
Deleting Columns: If the last data in Row 1 is "W1", then delete all columns after "W1"<o:p></o:p>
<o:p></o:p>
Any help will be appreciated. Thank you!<o:p></o:p>
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hello. Easily done but Excel will simply add blank rows and columns. What do you actually want to do?
 
Upvote 0
Code:
Sub Clear_BelowColA_RightRow1()

    Dim last as Long
    
    last = Range("A" & Rows.Count).End(xlUp).Row + 1
    Rows(last & ":" & Rows.Count).Clear
    
    last = Cells(1, Columns.Count).End(xlToLeft).Column + 1
    Range(Cells(1, last), Cells(1, Columns.Count)).EntireColumn.Clear
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,530
Messages
6,179,373
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top