Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default skip rows depending value of a particular cell in that row

I have a workbook with data elements in column A to F and about 1500 rows
(will increase). Column D sometime has the value "not assigned". I would like
to get subset of the data by leaving "not assigned" rows out. I have written
code to look at each from row 1 to end to check for "not assigned" in column
D and drop that row. It work but takes a while to run and as the file will be
getting larger with time it willl take longer.

Can anyone help with more efficient code?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default skip rows depending value of a particular cell in that row

The way of speeding up the code is to use an auxilary column putting a
character like 0 in the new column insteading of deleting the rows one at a
time. Then sort on the new column in descending order bringing all the 0's
to the top of the sorted area. Then deleting all the rows with zeroes.

Use this code
Sub test()
'Use column K as auxilary column
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Set SortRange = Range("A1:K" & Lastrow)
SortRange.Sort _
key1:=Range("K1"), _
order1:=xlDescending
Lastrow = Range("K" & Rows.Count).End(xlUp).Row
Rows("1:" & Lastrow).Delete

End Sub




"Prema" wrote:

I have a workbook with data elements in column A to F and about 1500 rows
(will increase). Column D sometime has the value "not assigned". I would like
to get subset of the data by leaving "not assigned" rows out. I have written
code to look at each from row 1 to end to check for "not assigned" in column
D and drop that row. It work but takes a while to run and as the file will be
getting larger with time it willl take longer.

Can anyone help with more efficient code?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default skip rows depending value of a particular cell in that row

Hi

I entered a formula to get 0 in K1 and copied the formula all the way down.
This is the only way I know to do without processing each row. Code for
sorting works OK but last row on K still gives me last row as before rather
than last row wich has 0. This is to do with the way I set the values in K
but don't know how to get 0 only where required and leave other cells
untouched .

Do you know how i CAN GET OVER THIS PROBLEM?

"Joel" wrote:

The way of speeding up the code is to use an auxilary column putting a
character like 0 in the new column insteading of deleting the rows one at a
time. Then sort on the new column in descending order bringing all the 0's
to the top of the sorted area. Then deleting all the rows with zeroes.

Use this code
Sub test()
'Use column K as auxilary column
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Set SortRange = Range("A1:K" & Lastrow)
SortRange.Sort _
key1:=Range("K1"), _
order1:=xlDescending
Lastrow = Range("K" & Rows.Count).End(xlUp).Row
Rows("1:" & Lastrow).Delete

End Sub




"Prema" wrote:

I have a workbook with data elements in column A to F and about 1500 rows
(will increase). Column D sometime has the value "not assigned". I would like
to get subset of the data by leaving "not assigned" rows out. I have written
code to look at each from row 1 to end to check for "not assigned" in column
D and drop that row. It work but takes a while to run and as the file will be
getting larger with time it willl take longer.

Can anyone help with more efficient code?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default skip rows depending value of a particular cell in that row

You can use PasteSpecial Values to get rid of the formula

Sub test()
'Use column K as auxilary column
Columns("K").copy
Columns("K").PasteValue Paste:=xlPasteValues
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Set SortRange = Range("A1:K" & Lastrow)
SortRange.Sort _
key1:=Range("K1"), _
order1:=xlDescending
Lastrow = Range("K" & Rows.Count).End(xlUp).Row
Rows("1:" & Lastrow).Delete

End Sub


"Prema" wrote:

Hi

I entered a formula to get 0 in K1 and copied the formula all the way down.
This is the only way I know to do without processing each row. Code for
sorting works OK but last row on K still gives me last row as before rather
than last row wich has 0. This is to do with the way I set the values in K
but don't know how to get 0 only where required and leave other cells
untouched .

Do you know how i CAN GET OVER THIS PROBLEM?

"Joel" wrote:

The way of speeding up the code is to use an auxilary column putting a
character like 0 in the new column insteading of deleting the rows one at a
time. Then sort on the new column in descending order bringing all the 0's
to the top of the sorted area. Then deleting all the rows with zeroes.

Use this code
Sub test()
'Use column K as auxilary column
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Set SortRange = Range("A1:K" & Lastrow)
SortRange.Sort _
key1:=Range("K1"), _
order1:=xlDescending
Lastrow = Range("K" & Rows.Count).End(xlUp).Row
Rows("1:" & Lastrow).Delete

End Sub




"Prema" wrote:

I have a workbook with data elements in column A to F and about 1500 rows
(will increase). Column D sometime has the value "not assigned". I would like
to get subset of the data by leaving "not assigned" rows out. I have written
code to look at each from row 1 to end to check for "not assigned" in column
D and drop that row. It work but takes a while to run and as the file will be
getting larger with time it willl take longer.

Can anyone help with more efficient code?

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
MACRO PASTE CELL to COLUMN, SKIP ROWS Dan Excel Discussion (Misc queries) 1 February 2nd 10 01:03 PM
Concatenate Rows depending on cell value in rows Pman Excel Programming 1 February 9th 08 10:33 PM
Delete rows depending on cell Value Tomas Stroem Excel Programming 3 June 8th 07 10:36 AM
adding rows depending on cell value [email protected] Excel Worksheet Functions 1 February 18th 07 04:18 PM
conditional formating on rows & cols depending on one cell bandy2000 Excel Discussion (Misc queries) 1 March 7th 06 11:46 PM


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

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

About Us

"It's about Microsoft Excel"