enter in last row in a set range

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I would like to enter an entry from the last row of a table that ends at A12. Using the code below is only useful if I use the entire range (A:A). Since I have limited my entries (A3:A12), I would like to check for the last empty row in rows A3:A12 and make my entry. How can I adjust the code to accomplish this task. Thanks

Code:
LastRow = Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row
 
Just another possible way (and just in case there ever could be 2 blanks in the range)...

Code:
Range("A3:12").Find("*", , xlValues, , xlByRows, xlPrevious)(2).Row


I tried you code, however it creates a "Method 'Range' of 'Object' failed message.

I like to try it because I getting an error when i start with a black sheet. See code....

Code:
Dim LastRow As Long

LastRow = Range("A3:12").Find("*", , xlValues, , xlByRows, xlPrevious)(2).Row


If Range("A12") > vbNullString Then MsgBox "You've reach the maximum trading limit!", vbExclamation: Exit Sub


Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:=""
If cbAct = "Buy" Then
    If Not tbXPrice.Visible Or tbXPrice = 0 Then
        MsgBox "Strike Price Has Not Been Entered!", vbCritical
        lbSPrice.Caption = "Strike Price"
        lbSQoute.Visible = False
        tbXPrice.Visible = True
        tbXPrice = 0
        tbXPrice.SetFocus
        
        With tbXPrice
            .SelStart = 0
            .SelLength = Len(.Text)
        End With
    Else
        Range("A" & LastRow) = cbName
        Range("B" & LastRow) = lbName.Caption
        Range("D" & LastRow) = Format(tbSDate, "mm/dd/yyyy")
        Range("E" & LastRow) = cbType
        Range("F" & LastRow) = tbOTotal
        Range("G" & LastRow) = CDbl(tbXPrice)
        Range("H" & LastRow) = Format(tbEDate, "mm/dd/yyyy")
        Range("J" & LastRow) = CDbl(tbAPrice)
        Range("K" & LastRow) = CDbl(tbBFee) + CDbl(tbOFee)
        Range("L" & LastRow) = CDbl(lbCost)
        Range("A3:Q12").Sort Key1:=Range("D3"), Order1:=xlAscending, Header:=xlNo
        MsgBox "Transaction Complete!", vbInformation
        NewOption
    End If
ActiveSheet.Protect Password:=""
Application.ScreenUpdating = True
 
Last edited:
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Code:
Sub test4()
    Dim LastRow As Long
    If Range("A12") > vbNullString Then MsgBox "You've reach the maximum trading limit!", vbExclamation: Exit Sub
    If WorksheetFunction.CountA(Range("A3:A11")) = 0 Then
        LastRow = 3
    Else
        LastRow = Range("A3:[COLOR="#FF0000"]A[/COLOR]11").Find("*", , xlValues, , xlByRows, xlPrevious)(2).Row
    End If
    MsgBox LastRow
End Sub
 
Upvote 0
I get an error on this line of code...I think is has something to do with the column letters....

Range("B" & LastRow) = lbName.Caption

Code:
Sub test4()
    Dim LastRow As Long
    If Range("A12") > vbNullString Then MsgBox "You've reach the maximum trading limit!", vbExclamation: Exit Sub
    If WorksheetFunction.CountA(Range("A3:A11")) = 0 Then
        LastRow = 3
    Else
        LastRow = Range("A3:[COLOR=#FF0000]A[/COLOR]11").Find("*", , xlValues, , xlByRows, xlPrevious)(2).Row
    End If
    MsgBox LastRow
End Sub
 
Upvote 0
What error? LastRow is just a number.
 
Last edited:
Upvote 0
When I run the code, it highlights this....

Code:
[COLOR=#333333]Range("B" & LastRow) = lbName.Caption[/COLOR]

If I take it out, it highlights the next line of code.
 
Upvote 0
Disregard....I discovered my error. The sheet was getting protected after the first entry in column A. My apologies..

Thank you Mark for esteem patience. Really grateful for you help.
 
Upvote 0

Forum statistics

Threads
1,224,944
Messages
6,181,927
Members
453,072
Latest member
jtees4

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