PC Review


Reply
Thread Tools Rate Thread

Clear Contents of Specific Cells in Last Row

 
 
Steve
Guest
Posts: n/a
 
      16th Mar 2009
Hi all. How can I have VBA clear the contents of the cells in the
LAST ROW in columns A,C,F, and K? The last row will vary, so VBA
needs to determine which row is the last. The columns will remain
static.

Thanks!
 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      16th Mar 2009
Sub test()
Dim lastrow As Long
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("A" & lastrow).ClearContents
Range("C" & lastrow).ClearContents
Range("F" & lastrow).ClearContents
Range("K" & lastrow).ClearContents
End Sub

"Steve" wrote:

> Hi all. How can I have VBA clear the contents of the cells in the
> LAST ROW in columns A,C,F, and K? The last row will vary, so VBA
> needs to determine which row is the last. The columns will remain
> static.
>
> Thanks!
>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      16th Mar 2009
Try code like the following:

Sub AAA()
Dim LastCell As Range
Dim WS As Worksheet
Dim N As Long
Dim Cols As Variant

Cols = Array("A", "C", "F", "K")
Set WS = ActiveSheet
With WS
For N = LBound(Cols) To UBound(Cols)
Set LastCell = .Cells(.Rows.Count, Cols(N)).End(xlUp)
LastCell.Delete shift:=xlUp
Next N
End With
End Sub

This deletes the last value in each of the columns. It supports the
case when the columns have different lengths.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Mon, 16 Mar 2009 14:21:00 -0700 (PDT), Steve
<(E-Mail Removed)> wrote:

>Hi all. How can I have VBA clear the contents of the cells in the
>LAST ROW in columns A,C,F, and K? The last row will vary, so VBA
>needs to determine which row is the last. The columns will remain
>static.
>
>Thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear Contents Of Cells Where Value = 0 =?Utf-8?B?Y2FybA==?= Microsoft Excel Worksheet Functions 3 6th Jul 2007 06:02 PM
Is there a formula to clear the contents of a specific cell? Bob Smith Microsoft Excel Worksheet Functions 2 9th Dec 2006 07:41 PM
Hid and unhide and clear contents for specific columns at the same time hamad.fatima@gmail.com Microsoft Excel Discussion 1 22nd Aug 2006 05:26 PM
clear contents cells of unprotected cells =?Utf-8?B?RWQ=?= Microsoft Excel Programming 6 12th Jan 2006 06:09 PM
counting specific figures in cells dependant upon contents of adjacent cells judoist Microsoft Excel Discussion 2 15th Jun 2004 02:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:30 PM.