finalrow = Cells(Rows.Count, 1).End(xlUp).Row - Final Row showing as 0

KMGIL

New Member
Joined
Dec 16, 2014
Messages
26
Hi
I am trying to create a macro to copy data from one sheet to another
The data is not copying across

Below is my code, the final row appears to be 0

Appreciate any thoughts

Thanks

kind Regards

ken


Code:
Sub Macro1()
'
' Macro1 Macro : Extract data to another Sheet


'




Dim datasheet As Worksheet 
Dim reportsheet As Worksheet 
Dim emailname As String
Dim finalrow As Integer
Dim i As Integer


' set variables


Set datasheet = Sheet2
Set reportsheet = Sheet3
emailname = reportsheet.Range("C2").Value


' clear old data 
reportsheet.Range("A3:L1000").ClearContents


'gotodata sheet and starts earching and copying
datasheet.Select
finalrow = Cells(Rows.Count, 1).End(xlUp).Row




' loop
For i = 2 To finalrow
If Cells(i, 2) = emailname Then
Range(Cells(i, 1), Cells(1, 12)).Copy
reportsheet.Select
Range("A1000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
datasheet.Select


End If


Next i


reportsheet.Select
Range("A2").Select


MsgBox "Data Copied"




'
End Sub
 
Last edited by a moderator:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Finalrow couldn't be less than 1 once that line has run, although you should use Long not Integer for a row number variable.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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