Store Cell Value In Variable

I am trying to store the value of a cell in a variable using vba. My code throws an error, what should I change so that the value of the cell is stored in my variable?

Dim total As Long
total = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).End.Value
Debug.Print (total)

The error I get is

Wrong number of arguments or invalid property assigned

Upvotes: 1

Views: 6147

Answers (1)

Stupid_Intern
Stupid_Intern

Reputation: 3450

Dim total As Long
Dim wk as worksheet

Set wk = activesheet

total = wk.Range("D" & wk.Cells(wk.Rows.Count, "D").End(xlUp).Row).value
Debug.Print (total)

Upvotes: 4

Related Questions