Find last available row in a range of cells

SSF1590

Board Regular
Joined
Oct 20, 2019
Messages
73
Hello,

I am looking to make a code work in the way that it finds the last available empty row in columns A to L since M will have data pull with a formula. But I am not sure how to or where to add the range to make it work. Can I please ave your help?

Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PCARDatabase")


iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1




If Trim(Me.TextBox1.Value) = "" Then
Me.TextBox1.SetFocus
Exit Sub


End If


With ws
' .Unprotect Password:="password"
.Cells(iRow, 1).Value = Me.TextBox1.Value
.Cells(iRow, 2).Value = Me.TextBox17.Value
.Cells(iRow, 3).Value = Me.ComboBox2.Value
.Cells(iRow, 4).Value = Me.TextBox2.Value
.Cells(iRow, 5).Value = Me.TextBox3.Value
.Cells(iRow, 6).Value = Me.TextBox4.Value
.Cells(iRow, 7).Value = Me.TextBox5.Value
.Cells(iRow, 8).Value = Me.TextBox6.Value
.Cells(iRow, 9).Value = Me.TextBox8.Value
.Cells(iRow, 10).Value = Me.TextBox9.Value
.Cells(iRow, 11).Value = Me.TextBox10.Value
.Cells(iRow, 12).Value = Me.ComboBox1.Value
' .Protect Password:="password"

Thank you.
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

PCL

Well-known Member
Joined
Jul 15, 2008
Messages
1,348
For me it's working right, the range is mentioned in ws.Cells
Did you check iRow value ??
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,680
Office Version
365
Platform
Windows
Try
Code:
ws.range("A:L").Find(What:="*"
 

Forum statistics

Threads
1,089,602
Messages
5,409,231
Members
403,256
Latest member
Viq

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top