5

This may seem too easy, but I am so desperate.

What I need to do is get the last value of the column "D" which has a

big amount of number, ex. 987654321, the code is fine if the value is only two-digit. I just can't identify the problem.

Dim lastRow As Long
lastRow = Cells(Rows.Count, "D").End(xlUp).Value
Sheets("Sheet1").TxtBox1.Value = lastRow
4
  • The above code works for me... Commented Mar 22, 2013 at 8:44
  • even with big amount of number? like 3000000000? 3million? Commented Mar 22, 2013 at 8:47
  • 2
    For values like 3000000000 declare lastRow as Double Commented Mar 22, 2013 at 8:48
  • You may want to see this? msdn.microsoft.com/en-us/library/office/… Commented Mar 22, 2013 at 8:50

2 Answers 2

12

Like I mentioned in my comment, for such large number you have to declare it as a double.

Dim lastRow As Double

Alternatively since you want to store it in a textbox you can do 2 things

  1. Declare it as a string
  2. Store it directly in the Textbox.

    Option Explicit
    
    Sub Sample1()
        Dim lastRow As String
    
        With Sheets("Sheet1")
            lastRow = .Cells(.Rows.Count, "D").End(xlUp).Value
            .TextBox1.Value = lastRow
        End With
    End Sub
    
    Sub Sample2()
        With Sheets("Sheet1")
            .TextBox1.Value = .Cells(.Rows.Count, "D").End(xlUp).Value
        End With
    End Sub
    
Sign up to request clarification or add additional context in comments.

Comments

4

Long can only handle values up to 2.1B! For any larger values, better use Double instead of Long

1 Comment

lol, silly me. Just trying to cope up with the deadline. But THANK YOU SO MUCH for the word DOUBLE.. :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.