LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default range.copy not working as expected

The copy method of the range object does not seem to be working as I
expect. Im sure it has something to do with how I have written the
destination. Below Ive included the function Im using it in. the rest of
the macro and the function itself works fine when I dont include the
copy. Information that may be helpful:

filteredRange is a range of filtered rows. It is not always contiguous.
The solution must work on non contiguous data, but I dont think that it
will matter much, since right now I can not get it to cooperate with
contiguous data. filteredRange is Set filteredRange =
ActiveSheet.AutoFilter.Range.Offset(1, 0).SpecialCells
(xlCellTypeVisible). I do have a special function if the range is not
contiguous. The filteredRange will be one or more rows. Rarely will it be
less than 3 rows. If the range is not contiguous when I do the copy, I do
not want the blank unfiltered data copied (again i don't think that would
be an issue, but worth mentioning just incase).

otpWS is the worksheet that conatains the filtered information. It belongs
to a workbook that has 9 other worksheets. filteredRange is the result of
applying the filter to otpWS. I am trying to copy the range to another
sheet in the same workbook.

The commented code under the line, copy range to appropriate worksheet are
my failed attempts.

The uncommented copy code works, but is not what I want. It will overwrite
what I have previously copied. I would like to the specific terminal sheet
to show all its information. otpTerminalSheetRowIndex keeps up with how
many rows have been used so far. It is incremented after the performOTP is
run. (if I have copied 30 rows so far I want to copy current data starting
at row 31).

Im writing on excel2003, but the final product must work on excel2000

If there is a method with less overhead than copying that will keep my
cell formatting/colors, I would love to hear about it as well.

The code:

Function performOTP(ByRef filteredRange As Range, ByVal
filteredRangeRowCount As Integer) As Integer
Dim earlyLateAllowence As Date
Dim earlyLateCount As Byte
earlyLateCount = 0
Dim xCtr As Byte
Dim timeVariance As Date
Dim actual As Date
Dim sched As Date
otpWS.Activate
With filteredRange.Areas(1)
For xCtr = 1 To filteredRangeRowCount
'this is the allowed time for the stop to be early or late.
'it varies by customer
earlyLateAllowence = whichAllowence(UCase(whichCustomer( _
.Rows(xCtr).Cells(1, otpCBID).Value))) actual =
TimeValue(.Rows(xCtr).Cells(1, otpColActual).Value) sched =
TimeValue(.Rows(xCtr).Cells(1, otpColSched).Value)

'if actual is greater than scheduled, the route was late ....
With .Rows(xCtr).Cells(1, otpColVariance)

If actual = sched Then
.NumberFormat = "hh:mm"
.Value = actual - sched
End If

If actual sched Then
timeVariance = actual - sched
'now check to see if it was over the allowed time. if so
'color cell red and increase earlyLateCount
'With .Rows(xCtr).Cells(xCtr, otpColVariance)
If timeVariance earlyLateAllowence Then
.Interior.ColorIndex = 3 'red
earlyLateCount = earlyLateCount + 1
End If
.NumberFormat = "hh:mm"
.Value = timeVariance
'End With
End If

'actual is less than scheduled, then the route was early If
actual < sched Then
timeVariance = sched - actual
'now check to see if it was over the allowed time. if so
'color cell yellow
'With .Rows(xCtr).Cells(xCtr, otpColVariance)
If timeVariance earlyLateAllowence Then
.Interior.ColorIndex = 6 'yellow
earlyLateCount = earlyLateCount + 1
End If
.NumberFormat = "hh:mm"
.Value = timeVariance
'End With
End If
End With
Next xCtr
'copy the filtered data to appropiate sheet. '''''''does not work,
but is what i
want?''''''''''''''''''''''''''''''''''''''' ' filteredRange.Copy
Destination:=Sheets(terminalNames (whichTerminalIndex)).Range( _ '
Sheets(terminalNames(whichTerminalIndex)).Cells
(otpTerminalSheetRowIndex( _
' whichTerminalIndex), 1))
' Sheets(terminalNames(whichTerminalIndex)).Activate
'.Insert shift:=xlShiftDown
'filteredRange.Select
'Selection.Insert shift:=xlShiftDown

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''
''''''works, but not what i
want'''''''''''''''''''''''''''''''''''''''
.Copy Destination:=Sheets(terminalNames(whichTerminalInd ex)).Range
("A1")

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''

End With
'return the number of lates/early the route had
Worksheets("Sheet1").Activate
performOTP = earlyLateCount
End Function


TIA
bst

 
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
Help !!! My code is not working as expected. Ayo Excel Discussion (Misc queries) 3 August 30th 07 10:39 PM
Iserror not working as expected NathanG Excel Worksheet Functions 5 February 1st 07 05:31 PM
=NETWORKDAYS not working as expected and as it once did USAOz Excel Worksheet Functions 2 July 13th 06 03:02 PM
For Each Statement not working as expected Jacqui Excel Programming 1 November 2nd 05 12:19 PM
Lookup Not working as expected trumpy81 New Users to Excel 5 June 30th 05 07:41 PM


All times are GMT +1. The time now is 10: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"