Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Code to delete rows with varying amounts of data

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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code to delete rows with varying amounts of data


do yo have a Header Row (Row 1) or some other row?

If you have a header row in row 1

'check if cell K2 is empty
if range("K2") < "" then
FirstRow = Range("K2").end(xldown).Row
LastrEmpty = FirstRow -1
rows("2:" & LastEmpty).delete
end if


If you don't have aheader row

'check if cell K1 is empty
if range("K1") < "" then
FirstRow = Range("K1").end(xldown).Row
LastrEmpty = FirstRow -1
rows("1:" & LastEmpty).delete
end if


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?u=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=195160

http://www.thecodecage.com/forumz

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Code to delete rows with varying amounts of data

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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Code to delete rows with varying amounts of data

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting rows of data of varying lengths NDBC Excel Discussion (Misc queries) 12 July 4th 09 12:44 PM
getting data from an array of varying amounts of comboboxes [email protected] Excel Programming 1 June 20th 07 06:39 PM
Insert totals after varying rows of data prodeji Excel Programming 1 February 13th 07 01:40 AM
Creating Pivot tables by VBA for varying amounts of data Paul Excel Programming 3 December 12th 06 10:07 PM
Remove varying amounts of space characters Access Joe Excel Discussion (Misc queries) 4 January 13th 06 10:28 PM


All times are GMT +1. The time now is 08:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"