VBA Delete Last 4 Columns of data

backfromthebush

New Member
Joined
Jul 2, 2010
Messages
37
Hi all,

I have a spreadsheet that has a whole heap of data. I just need a simple code that when run will delete the last four columns of data. The column locations may be different each time i run the code (e.g. one time it could be V:Z, and the next it could be N:Q, etc.).

And similarly, I need it to delete the last row of data as well, which could also be on a different row each time.

Basically the last four columns and the last row contain a summary total of the data, which I dont want.

Any suggestions?
 
Last edited:

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,278
Code:
Sub Delete_Last()

    Dim Last As Long
    
    On Error Resume Next
    
    ' Last column
    Last = Cells.Find("*", , , , xlByColumns, xlPrevious).Column
    ' Delete last 4 columns
    If Last >= 4 Then Columns(Last - 3).Resize(, 4).Delete

    ' Last row
    Last = 0
    Last = Cells.Find("*", , , , xlByRows, xlPrevious).Row
    ' Delete last row
    If Last > 0 Then Rows(Last).Delete
    
    On Error GoTo 0
    
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,436
Messages
5,528,758
Members
409,834
Latest member
vexceled

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top