PC Review


Reply
Thread Tools Rate Thread

Code to delete rows with varying amounts of data

 
 
Zakynthos
Guest
Posts: n/a
 
      13th Apr 2010
Hi,

I have a macro whcih sorts data on column K on one tab then pastes the data
onto a new tab conntaining Lookup formula.

My problem is that the rows pasted contain varying amounts of data and
ideally I would like some code which I incorporate into the current macro
whichi would:
1. locate the first row in Column K which is empty
2. Select columns A:P for this row (whcih DO contain data) and all columns
below this empty column/row (K)
3. Delete all the data in these rows.

Thanks for your help.


 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      13th Apr 2010
Try

Sub Macro()

Dim lngLastRow1 As Long, lngLastRow2 As Long

lngLastRow1 = Cells(Rows.Count, "K").End(xlUp).Row + 1
lngLastRow2 = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row

If lngLastRow2 > lngLastRow1 Then
Rows(lngLastRow1 & ":" & lngLastRow2).ClearContents
End If

End Sub

--
Jacob (MVP - Excel)


"Zakynthos" wrote:

> Hi,
>
> I have a macro whcih sorts data on column K on one tab then pastes the data
> onto a new tab conntaining Lookup formula.
>
> My problem is that the rows pasted contain varying amounts of data and
> ideally I would like some code which I incorporate into the current macro
> whichi would:
> 1. locate the first row in Column K which is empty
> 2. Select columns A:P for this row (whcih DO contain data) and all columns
> below this empty column/row (K)
> 3. Delete all the data in these rows.
>
> Thanks for your help.
>
>

 
Reply With Quote
 
Zakynthos
Guest
Posts: n/a
 
      13th Apr 2010
Jacob,

Fantastic! - works perfectly - thank you so much for your help and quick
response.

"Jacob Skaria" wrote:

> Try
>
> Sub Macro()
>
> Dim lngLastRow1 As Long, lngLastRow2 As Long
>
> lngLastRow1 = Cells(Rows.Count, "K").End(xlUp).Row + 1
> lngLastRow2 = ActiveSheet.Cells.Find(What:="*", _
> SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
>
> If lngLastRow2 > lngLastRow1 Then
> Rows(lngLastRow1 & ":" & lngLastRow2).ClearContents
> End If
>
> End Sub
>
> --
> Jacob (MVP - Excel)
>
>
> "Zakynthos" wrote:
>
> > Hi,
> >
> > I have a macro whcih sorts data on column K on one tab then pastes the data
> > onto a new tab conntaining Lookup formula.
> >
> > My problem is that the rows pasted contain varying amounts of data and
> > ideally I would like some code which I incorporate into the current macro
> > whichi would:
> > 1. locate the first row in Column K which is empty
> > 2. Select columns A:P for this row (whcih DO contain data) and all columns
> > below this empty column/row (K)
> > 3. Delete all the data in these rows.
> >
> > Thanks for your help.
> >
> >

 
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
Sorting rows of data of varying lengths NDBC Microsoft Excel Misc 12 4th Jul 2009 12:44 PM
getting data from an array of varying amounts of comboboxes lar.thegreat@gmail.com Microsoft Excel Programming 1 20th Jun 2007 06:39 PM
Insert totals after varying rows of data prodeji Microsoft Excel Programming 2 13th Feb 2007 02:17 PM
Creating Pivot tables by VBA for varying amounts of data Paul Microsoft Excel Programming 3 12th Dec 2006 10:07 PM
Returning varying rows of data through lookup function NewbieNerd Microsoft Excel Programming 1 26th Aug 2004 06:07 PM


Features
 

Advertising
 

Newsgroups
 


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