Last cell value copy error

drluke

Active Member
Joined
Apr 17, 2014
Messages
314
Office Version
  1. 365
Platform
  1. Windows
I want to copy the value in the last cell in a column to a cell in another worksheet, and add 1 to it.
I don't know why this code gives a type mismatch error?
VBA Code:
Sub copyValue()

Sheets("Additions").Range("A47").Value = Sheets("Test FAR").Range("A" & Rows.Count).End(xlUp).Value + 1
     
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Sounds like the value it is returning is not a number you can add to.
What does this test return?
VBA Code:
Sub Test()
    MsgBox Sheets("Test FAR").Range("A" & Rows.Count).End(xlUp).Value
End Sub
 
Upvote 0
I would do it like this
VBA Code:
Sub copyValue()

lRow = Sheets("Test FAR").Cells(Rows.Count, 1).End(xlUp).Value
Sheets("Additions").Range("A47").Value = lRow + 1     

End Sub
 
Upvote 0
I would do it like this
VBA Code:
Sub copyValue()

lRow = Sheets("Test FAR").Cells(Rows.Count, 1).End(xlUp).Value
Sheets("Additions").Range("A47").Value = lRow + 1  

End Sub
That shouldn't really make any difference.
And note that they are NOT trying to get the last row number in column A, but rather the value of the last populated cell in column A.
 
Upvote 0
That shouldn't really make any difference.
And note that they are NOT trying to get the last row number in column A, but rather the value of the last populated cell in column A.
Yes I know it shouldn't make a difference but it makes it easier to locate the error
 
Upvote 0

Forum statistics

Threads
1,216,753
Messages
6,132,516
Members
449,732
Latest member
Viva

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