Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Active sort / Copy

Novice
Excel 2003

My additions to a "ImportBigFile" macro by C. Pearson is working nicely
thanks to several here - thanks. Found I have a wee bit of a problem though
if there are no entries for a device.

Here's what I'm doing briefly:

Have a log file that has 200,000 + records

I import it and fill a worksheet to 64K, then start another until the EOF is
reached. This raw data has a header row at the top of each page (row 5) and
I'm only using columns A-F on each page of raw data.

I then add a sheet for each of the 30 devices and then copy the header from
the first raw data sheet over to the 30 device sheets. The raw data is then
sorted using the active filter and all the imported raw data is then copied
over to it's respective device sheet. Works great. All device numbers in
the raw data sheets end up on the correct sheets - no problems.

But.... if there are no entries (log records) for say device 21, for some
reason as each of the raw data sheets are scanned and no data is
found/filtered, an additional header row is placed under the original header
row on the device sheet. This will occur for each raw data sheet that is
filtered.

So if I have 5 sheets of raw data, they are all scanned, no data found for
the device (since there is none) and then 5 additional header rows are
placed below row 5's.

Here's a snippet of the code:

I = 0
For I = 1 To RawDataShts 'Filter the raw imported data on each Data
sheet and sort it, then copy it to it's respective number sheet
Worksheets(I).Activate
UnitNum = 0
For T = 1 To 30

UnitNum = UnitNum + 1 'filter on the Unit Number of the equipment

'routine is sorting on the Unit number.
If T < 10 Then
[B5].CurrentRegion.AutoFilter Field:=2, Criteria1:="=*RTMS
0" & T & "*" 'filter can't deal with 01, 02...09 numbers. It drops leading
zero so use the "0" in front to filter on
Range([A5], Range("F" &
[A5].SpecialCells(xlLastCell).Row)).SpecialCells(xlCel lTypeVisible).Copy _
Sheets("RTMS-" & UnitNum).Range("A" & Sheets("RTMS-" &
UnitNum).[A5].SpecialCells(xlLastCell).Row + 1)

Else 'this catches devices number 10 to 30
[B5].CurrentRegion.AutoFilter Field:=2, Criteria1:="=*RTMS "
& T & "*" 'this get everyting else for units 10 to 30
Range([A5], Range("F" &
[A5].SpecialCells(xlLastCell).Row)).SpecialCells(xlCel lTypeVisible).Copy _
Sheets("RTMS-" & UnitNum).Range("A" & Sheets("RTMS-" &
UnitNum).[A5].SpecialCells(xlLastCell).Row + 1)
End If

Next T
Selection.AutoFilter 'turn off the autofilter function on the Data
sheets
Next I

How can I test if a device number has no data and simply jump out and on to
the next one, or test for no data and decrement the row count so that row is
overwritten?

Thanks,

Bob S.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Active sort / Copy

After the autofilter statement, you could put an If statement that If (same
range to copy). SpecialCells(xlCellTypeVisible).Count < 1 Tthen Exit For.
That should take you to the next sheet.

"BobS" wrote:

Novice
Excel 2003

My additions to a "ImportBigFile" macro by C. Pearson is working nicely
thanks to several here - thanks. Found I have a wee bit of a problem though
if there are no entries for a device.

Here's what I'm doing briefly:

Have a log file that has 200,000 + records

I import it and fill a worksheet to 64K, then start another until the EOF is
reached. This raw data has a header row at the top of each page (row 5) and
I'm only using columns A-F on each page of raw data.

I then add a sheet for each of the 30 devices and then copy the header from
the first raw data sheet over to the 30 device sheets. The raw data is then
sorted using the active filter and all the imported raw data is then copied
over to it's respective device sheet. Works great. All device numbers in
the raw data sheets end up on the correct sheets - no problems.

But.... if there are no entries (log records) for say device 21, for some
reason as each of the raw data sheets are scanned and no data is
found/filtered, an additional header row is placed under the original header
row on the device sheet. This will occur for each raw data sheet that is
filtered.

So if I have 5 sheets of raw data, they are all scanned, no data found for
the device (since there is none) and then 5 additional header rows are
placed below row 5's.

Here's a snippet of the code:

I = 0
For I = 1 To RawDataShts 'Filter the raw imported data on each Data
sheet and sort it, then copy it to it's respective number sheet
Worksheets(I).Activate
UnitNum = 0
For T = 1 To 30

UnitNum = UnitNum + 1 'filter on the Unit Number of the equipment

'routine is sorting on the Unit number.
If T < 10 Then
[B5].CurrentRegion.AutoFilter Field:=2, Criteria1:="=*RTMS
0" & T & "*" 'filter can't deal with 01, 02...09 numbers. It drops leading
zero so use the "0" in front to filter on
Range([A5], Range("F" &
[A5].SpecialCells(xlLastCell).Row)).SpecialCells(xlCel lTypeVisible).Copy _
Sheets("RTMS-" & UnitNum).Range("A" & Sheets("RTMS-" &
UnitNum).[A5].SpecialCells(xlLastCell).Row + 1)

Else 'this catches devices number 10 to 30
[B5].CurrentRegion.AutoFilter Field:=2, Criteria1:="=*RTMS "
& T & "*" 'this get everyting else for units 10 to 30
Range([A5], Range("F" &
[A5].SpecialCells(xlLastCell).Row)).SpecialCells(xlCel lTypeVisible).Copy _
Sheets("RTMS-" & UnitNum).Range("A" & Sheets("RTMS-" &
UnitNum).[A5].SpecialCells(xlLastCell).Row + 1)
End If

Next T
Selection.AutoFilter 'turn off the autofilter function on the Data
sheets
Next I

How can I test if a device number has no data and simply jump out and on to
the next one, or test for no data and decrement the row count so that row is
overwritten?

Thanks,

Bob S.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Active sort / Copy

After you filter the data, you can look at how many visible rows are in the
autofilter.range. If there's only one (the headers count), then you don't have
any data.

'actually just use the first column and count visible cells
dim VCells as long
vcells = activesheet.autofilter.range.columns(1) _
.cells.specialcells(xlcelltypevisible).cells.count
if vcells = 1 then
'only the headers
else
msgbox vcells -1 & " rows of data found!"
end if



BobS wrote:

Novice
Excel 2003

My additions to a "ImportBigFile" macro by C. Pearson is working nicely
thanks to several here - thanks. Found I have a wee bit of a problem though
if there are no entries for a device.

Here's what I'm doing briefly:

Have a log file that has 200,000 + records

I import it and fill a worksheet to 64K, then start another until the EOF is
reached. This raw data has a header row at the top of each page (row 5) and
I'm only using columns A-F on each page of raw data.

I then add a sheet for each of the 30 devices and then copy the header from
the first raw data sheet over to the 30 device sheets. The raw data is then
sorted using the active filter and all the imported raw data is then copied
over to it's respective device sheet. Works great. All device numbers in
the raw data sheets end up on the correct sheets - no problems.

But.... if there are no entries (log records) for say device 21, for some
reason as each of the raw data sheets are scanned and no data is
found/filtered, an additional header row is placed under the original header
row on the device sheet. This will occur for each raw data sheet that is
filtered.

So if I have 5 sheets of raw data, they are all scanned, no data found for
the device (since there is none) and then 5 additional header rows are
placed below row 5's.

Here's a snippet of the code:

I = 0
For I = 1 To RawDataShts 'Filter the raw imported data on each Data
sheet and sort it, then copy it to it's respective number sheet
Worksheets(I).Activate
UnitNum = 0
For T = 1 To 30

UnitNum = UnitNum + 1 'filter on the Unit Number of the equipment

'routine is sorting on the Unit number.
If T < 10 Then
[B5].CurrentRegion.AutoFilter Field:=2, Criteria1:="=*RTMS
0" & T & "*" 'filter can't deal with 01, 02...09 numbers. It drops leading
zero so use the "0" in front to filter on
Range([A5], Range("F" &
[A5].SpecialCells(xlLastCell).Row)).SpecialCells(xlCel lTypeVisible).Copy _
Sheets("RTMS-" & UnitNum).Range("A" & Sheets("RTMS-" &
UnitNum).[A5].SpecialCells(xlLastCell).Row + 1)

Else 'this catches devices number 10 to 30
[B5].CurrentRegion.AutoFilter Field:=2, Criteria1:="=*RTMS "
& T & "*" 'this get everyting else for units 10 to 30
Range([A5], Range("F" &
[A5].SpecialCells(xlLastCell).Row)).SpecialCells(xlCel lTypeVisible).Copy _
Sheets("RTMS-" & UnitNum).Range("A" & Sheets("RTMS-" &
UnitNum).[A5].SpecialCells(xlLastCell).Row + 1)
End If

Next T
Selection.AutoFilter 'turn off the autofilter function on the Data
sheets
Next I

How can I test if a device number has no data and simply jump out and on to
the next one, or test for no data and decrement the row count so that row is
overwritten?

Thanks,

Bob S.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Active sort / Copy

Thanks to you both. The checking if the visible cell count after copying the
data from the array worked nicely.

Thank you,

Bob S.


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
I need to sort an active sheet using the col of the active cell HamFlyer Excel Programming 3 June 6th 06 07:25 PM
Copy from active sheet and paste into new sheet using info from cell in active Ingve Excel Programming 3 January 23rd 06 09:57 PM
sort ascending tab is not active. Why? jeremy corke Excel Worksheet Functions 2 July 10th 05 12:00 AM
sort on not active sheet peter_bhp Excel Programming 4 December 25th 04 09:00 AM
HOW TO COPY 480 ACTIVE E-MAIL ADDRESSES CLM "G" ON AN ACTIVE EXCE. ragman10 Excel Discussion (Misc queries) 1 December 13th 04 11:52 PM


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

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"