get the last balance from last row in listbox into textbox on userform

Ali M

Active Member
Joined
Oct 10, 2021
Messages
290
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi
I search for way when search the item based on column D into textbox1 and populate the data in listbox should get the last balance from the last row is existed in listbox for the last column in listbox (H), and populate the last balance into textbox2
should not summing , just brings the last value from the last row for the last column in listbox to textbox2 .

here is the code
VBA Code:
Private Sub Searchbutton_Click()
    With Sheets("Inventory List")
        If IsError(Application.Match(TextBox1.Text, .Columns(4), 0)) Then MsgBox "Modelnumber not found!": Exit Sub
        r = .Range("A3", .Range("H" & .Rows.Count).End(xlUp)).Resize(, 9)
    End With
    With ListBox1
        .List = r
        .ColumnCount = UBound(r, 2)
        For i = 0 To .ListCount - 1
            .List(i, .ColumnCount - 1) = i + 3
        Next
        For i = .ListCount - 1 To 0 Step -1
            If UCase(.List(i, 3)) <> UCase(TextBox1.Text) Then .RemoveItem i
        Next
    End With
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Perhaps something like this
VBA Code:
TextBox1.Value = ListBox1.List(UBound(ListBox1.List, 1), UBound(ListBox1.List, 2))
near the end of your sub.
 
Upvote 0
thanks for your guessing , but unfortunately this is not what I look for it
based on your suggestion
this is what I got
DF.JPG

obviously indicate to last row number into sheet as I mark by red .
but what I want as marking by red for textbox,listbox
W.JPG

thanks again
 
Upvote 0
Try . . .

VBA Code:
    With Me.ListBox1
        Me.TextBox2.Value = .List(.ListCount - 1, .ColumnCount - 1)
    End With

Hope this helps!
 
Upvote 0
My understanding is that you want the list item from the last row and last column, correct? If so, maybe you have other columns that are hidden?

In any case, since I see now that you actually specified Column H, try the following instead...

VBA Code:
    With Me.ListBox1
        Me.TextBox2.Value = .Column(7, .ListCount - 1)
    End With

Note that column indexing starts at 0.

Hope this helps!
 
Upvote 0
Solution
My understanding is that you want the list item from the last row and last column, correct?
that's correct.
If so, maybe you have other columns that are hidden?
no ! there is no hidden
In any case, since I see now that you actually specified Column H, try the following instead...
it works perfectly (y)
thanks very much ;)
 
Upvote 0
Hmmm.... I don't understand why the solution offered by @rlv01 and myself didn't give you the desired result. Oh well, I'm glad you have what you need.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,215,697
Messages
6,126,269
Members
449,308
Latest member
VerifiedBleachersAttendee

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