counting

johnster

New Member
Joined
May 31, 2018
Messages
43
Can anyone help me with this?

I have a Textbox and a List box with a delete button so i can remove the last row. In my listbox there are 2 columns (1st names and 2nd prices). My textbox counts the second row (prices).
The delete button is doing it but does not counts down in my textbox. Can Someone complete the code please?

Here is my code so far without counting down.

Private Sub CommandButton84_Click()
Dim ItemTarget As Long
ItemTarget = ListBox1.ListCount
If ItemTarget > 0 Then
ListBox1.RemoveItem ItemTarget - 1
End If
End Sub




 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
When the user form closes, the code below opens another workbook, creates a sheet for this date and transfers the list box contents to that sheet.

Code:
Private Sub TextBox1_Change()
ThisWorkbook.Sheets("sheet6").Range("B20") = TextBox1
End Sub
 
Private Sub UserForm_QueryClose(Cancel%, CloseMode%)
Const wbn$ = "1200_status.xlsx"                     ' name of other workbook
Dim wb As Workbook, ws As Worksheet, wsn$, lb
Set lb = Me.ListBox1
wsn = Replace(Date, "/", "_")
If Not WbIsOpen(wbn) Then Workbooks.Open ("c:\pub\2017\" & wbn) ' your path here
Set wb = Workbooks(wbn)
If Not ShExists(wsn, wb) Then
    wb.Sheets.Add , wb.ActiveSheet
    wb.ActiveSheet.Name = wsn
End If
lr = wb.Sheets(wsn).Range("a" & Rows.Count).End(xlUp).Row + 1
wb.Sheets(wsn).Cells(lr, 1).Resize(lb.ListCount, lb.ColumnCount) = lb.List  ' copy to sheet
End Sub

Function ShExists(sname$, wb As Workbook) As Boolean
Dim x As Object
On Error Resume Next
Set x = wb.Sheets(sname)
ShExists = False
If Err.Number = 0 Then ShExists = True
End Function

Function WbIsOpen(wb) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wb)
WbIsOpen = False
If Err.Number = 0 Then WbIsOpen = True
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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