View Single Post
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

You can use application.match() to see if there's a date that matches:

Option Explicit
Sub testme()

Dim infoWks As Worksheet
Dim callWks As Worksheet
Dim res As Variant
Dim myRng As Range
Dim DestCell As Range

Set infoWks = Worksheets("infoloader")
Set callWks = Worksheets("callerinput")

Set myRng = infoWks.Range("b:b")

'sometimes converting to a long will make the match work better with dates.
res = Application.Match(CLng(callWks.Range("b29").Value) , myRng, 0)

If IsError(res) Then
Set DestCell = infoWks.Range("B" & LastRow(infoWks) + 1)
Else
Set DestCell = myRng(res)
End If

callWks.Range("b29:bq29").Copy _
Destination:=DestCell

End Sub

'my easy version of LastRow--for testing only
'use your own.
Function LastRow(wks As Worksheet) As Long
With wks
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
End Function

Steve wrote:

I have the following code to copy data from one sheet to another:

Sheets("CallerInput").Range("B29:BQ29").Copy _
Sheets("InfoLoader").Range("B" & LastRow(Sheets("InfoLoader")) + 1)

However, cell B29 in the range to be copied is a date. How can I amend
this code to first look down column B of the paste target in
"InfoLoader". It would then overtype any day already held, or otherwise
paste to the end?

Thanks in advance

Steve


--

Dave Peterson