LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy last row with data to next empty row...

This portion:

With destWB
Set destRange _
= cells(Rows.Count, "B").End(xlUp).Offset(1, 0).EntireRow
End With

is a problem.

When you have those unqualified ranges in a procedure in a general module, then
those ranges refer to the activesheet. If you're lucky, the correct sheet is
active. If you're not so lucky, then you won't get what you want. And the
"with destwb" isn't really doing anything.

But I had a problem in my code:

With destWB
Set destRange _
= .Cells(.Rows.Count, "B").End(xlUp).Offset(1, 0).EntireRow
End With

should have been:

With destWB.worksheets("whateverworksheetname")
Set destRange _
= .Cells(.Rows.Count, "B").End(xlUp).Offset(1, 0).EntireRow
End With

And this portion:

With ThisWorkbook 'source workbook?
Set sourceRange _
= .Worksheets("SP").Cells(.Rows.Count, "B").End(xlUp).EntireRow
End With

should have been:

With ThisWorkbook.worksheets("SP")
Set sourceRange _
= .Cells(.Rows.Count, "B").End(xlUp).EntireRow
End With


Sorry about the errors.


Oreg wrote:

Hi Dave,

I'm not sure why, but when I leave the dots, I keep getting the
following error:
"Method or data member not found"

As soon as I took the dots out, it worked fine. Any ideas why ? I'm
just curious because I'd like to get to the point....eventually...where
I actually know what I'm doing. Here's what the code looks like that
works error free for me.

Sub CopytoSP_history()

Dim sourceRange As Range
Dim destRange As Range
Dim destWB As Workbook

Application.ScreenUpdating = False

If bIsBookOpen("SPHistory.xls") Then
Set destWB = Workbooks("SPHistory.xls")
Else
Set destWB = Workbooks.Open("C:\EVENT TRACKER\TrackerLog\" & _
"METRO\SPhistory\SPHistory.xls")
End If

With destWB
Set destRange _
= cells(Rows.Count, "B").End(xlUp).Offset(1, 0).EntireRow
End With

With ThisWorkbook 'source workbook?
Set sourceRange _
= .Worksheets("SP").cells(Rows.Count, "B").End(xlUp).EntireRow
End With

sourceRange.Copy
destRange.PasteSpecial xlPasteValues, , False, False

Application.CutCopyMode = False
destWB.Close True
Application.ScreenUpdating = True
End Sub

Thanks,

Oreg

--
Oreg
------------------------------------------------------------------------
Oreg's Profile: http://www.excelforum.com/member.php...fo&userid=9195
View this thread: http://www.excelforum.com/showthread...hreadid=480972


--

Dave Peterson
 
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
formula to copy data to empty cell Olchannel New Users to Excel 1 September 27th 08 11:06 AM
How to copy data to the next empty cell in a column suruukko Excel Worksheet Functions 2 July 22nd 06 12:35 PM
Copy Data From Filled to Empty Cells Sheikh Saadi Excel Discussion (Misc queries) 0 November 10th 05 07:21 PM
Copy last row with data to next empty row... Oreg[_52_] Excel Programming 0 November 2nd 05 01:05 AM
macro to copy paste non empty data paritoshmehta[_22_] Excel Programming 0 July 1st 04 09:17 PM


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