charly1988
New Member
- Joined
- Jul 31, 2022
- Messages
- 13
- Office Version
- 2016
- Platform
- Windows
Hello everyone, as i am new to excel vba i need some help for running a progress bar while i add data from userform. When i click add button progress bar should run till the "adding data" code runs. And finally want to show a massage box too say that process is successful. Below is the simple code i use to add data from userform to excel worksheet.
Private Sub cmbAddItem_Click()
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ThisWorkbook.Sheets("ITEMS")
Dim rng As Range
Set rng = sht.Range("ITEM_LIST").CurrentRegion
LastRow = rng.End(xlDown).Row + 1
With sht
.Cells(LastRow, 3) = lblItemId
.Cells(LastRow, 4) = txtItemname
.Cells(LastRow, 5) = lblDate
.Cells(LastRow, 6) = txtItemDes
.Range("ITEM_LIST").Rows(rng.Rows.Count).Font.Name = "Franklin Gothic Book"
.Range("ITEM_LIST").Rows(rng.Rows.Count).HorizontalAlignment = xlCenter
End With
'--------------------------- load listbox or refresh listbox by class
loaditemlist
Call ItemCode ' update item code label for next item
lblTotItem = Application.CountA(Range("ITEM_CODE")) ' To Refresh
ThisWorkbook.Save
End sub
Thank you for your help in advance
Private Sub cmbAddItem_Click()
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ThisWorkbook.Sheets("ITEMS")
Dim rng As Range
Set rng = sht.Range("ITEM_LIST").CurrentRegion
LastRow = rng.End(xlDown).Row + 1
With sht
.Cells(LastRow, 3) = lblItemId
.Cells(LastRow, 4) = txtItemname
.Cells(LastRow, 5) = lblDate
.Cells(LastRow, 6) = txtItemDes
.Range("ITEM_LIST").Rows(rng.Rows.Count).Font.Name = "Franklin Gothic Book"
.Range("ITEM_LIST").Rows(rng.Rows.Count).HorizontalAlignment = xlCenter
End With
'--------------------------- load listbox or refresh listbox by class
loaditemlist
Call ItemCode ' update item code label for next item
lblTotItem = Application.CountA(Range("ITEM_CODE")) ' To Refresh
ThisWorkbook.Save
End sub
Thank you for your help in advance