Find last row

johnster

New Member
Joined
May 31, 2018
Messages
43
Why does my code not work? It always writes in row A

The code in green works fine.

Private Sub CommandButton100_Click()
Dim lItem As Long
Dim IRange As Integer

For lItem = 0 To ListBox1.ListCount - 1
ListBox1.ColumnCount = 2
With Worksheets("Sheet6")
.Cells(lItem + 5, 1) = ListBox1.List(lItem, 0)
.Cells(lItem + 5, 2) = ListBox1.List(lItem, 1)
End With

With Sheets("Histo")
Item = Worksheets("Histo").Cells(Rows.Count, 1).End(xlUp).Value
.Cells(lItem + 1, 1) = Date
.Cells(lItem + 1, 2) = ListBox1.List(lItem, 0)
.Cells(lItem + 1, 3) = ListBox1.List(lItem, 1)
End With
 
I will look at it if no-one else does when I get in tonight but just to clarify my earlier post you were using Item to define the last row but then not using it.

You were using IItem + 1 etc.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I will look at it if no-one else does when I get in tonight but just to clarify my earlier post you were using Item to define the last row but then not using it.

You were using IItem + 1 etc.

Mark,

Thank in advance. I really appreciate this.
 
Upvote 0
Code:
        With Sheets("Histo")
        LastRow = .Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
            .Cells(LastRow + 2, 1) = Date
            .Cells(LastRow + 2, 2) = ListBox1.List(LItem, 0)
            .Cells(LastRow + 2, 3) = ListBox1.List(LItem, 1)
        End With
 
Upvote 0
Code:
        With Sheets("Histo")
        LastRow = .Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
            .Cells(LastRow + 2, 1) = Date
            .Cells(LastRow + 2, 2) = ListBox1.List(LItem, 0)
            .Cells(LastRow + 2, 3) = ListBox1.List(LItem, 1)
        End With

Mark,

The code is working very well, Thank you very much for your patience with me :p

Little question, Is it possible when you selecting a row in a sheet to copy (with a commandbutton) again to your listbox?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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