LastRow problem

pirdop

Board Regular
Joined
Jul 27, 2010
Messages
72
Hi,
I try to copy the date from multiple summary sheets(in differentr wbs) in one new workbook called for the moment Summary_test.xls

The problem I encounter is that the lastRow=ActiveSheet.UsedRange.Rows.Count

doesn't return the actual last line but the lastRow used - 1, any ideas what's wrong ?

here is the code

Code:
Sub Summary_In_NewWorkbook()

Dim i As Double
Dim wbname As String

wbname = ActiveWorkbook.Name

    Workbooks(wbname).Activate
    Sheets("Summary").UsedRange.Copy
    Workbooks("Summary_test.xls").Activate
    LastRow = ActiveSheet.UsedRange.Rows.Count
    ' the msgBox was added after I detected the problem!
    MsgBox ("last row used is: " & LastRow & "lastrow+1= " & LastRow + 1)
    Cells(LastRow + 1, 1).Select
    Sheets("Sheet1").Paste



End Sub
Thank to all!

P.S. Of course with the lastrow+1 the first copied rows start from row 2 in the new workbook, which was not initially the idea
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
apparantely with each copy/paste operation made the error is increasing dynamically after 3 operations I'm getting 4 lines overlapping !???

Still don't get it why :eek:
 
Upvote 0
for those interested:

Strangely enough the first empty row was bugging the whole thing
so simple if check solved it

if isempty(cells(1,1))= true then
cells(1,1).select
Sheets(1).Paste
else
Rows(lastrow+1).select
Sheets(1).Paste
endif

although it's solved now I still don't understand this strange behaviour!
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,426
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top