Help with VBA code

MrPumper

New Member
Joined
Sep 11, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I need help with this code. I want to display that last 10 entries that are inputted on sheet 3 into 1stDisplay (List Box) of userform1. At the moment it displays this A4518:J65356. This works but would like to clean it up more. New entries are being made every day. Thank You below is code.



Private Sub cmdRemove_Click()
Dim wks As Worksheet
Dim AddNew As Range
Set wks = Sheet3


Dim s As String
s = "MA20-"


Set AddNew = wks.Range("A65356").End(xlUp).Offset(1, 0)

AddNew.Offset(0, 0).Value = txtBadge.Text
AddNew.Offset(0, 1).Value = s & txtpartnumber.Text
AddNew.Offset(0, 2).Value = txtquantity.Text
AddNew.Offset(0, 3).Value = txtmachine.Text


lstDisplay.ColumnCount = 5
lstDisplay.RowSource = "A4518:J65356"


Dim iControl As Control

For Each iControl In Me.Controls
If iControl.Name Like "txt*" Then iControl = vbNullString
Next

txtpartnumber.SetFocus

Dim ws As Worksheet
Dim rng As Range
Dim myVal As Range
Set ws = Sheet3
Set rng = ws.Range("C65356").End(xlUp)
For Each myVal In rng

Next myVal



ThisWorkbook.Save


End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I added this I think it works now.

Dim HowManyRows As Long
HowManyRows = 12
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
lstDisplay.ColumnCount = 7
lstDisplay.Clear
lstDisplay.List = Cells(Lastrow - HowManyRows + 1, 1).Resize(HowManyRows, 15).Value
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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