I've this macro in an UserForm to register accounting operations, after I finish the registration and I click the "x" button in the Userform my excel workbook close without asking me. I know this piece of code is the problem because my Userform do other things and these other things don't cause this problem.
Confirmar = MsgBox("¿Desea registrar la nueva operación contable?", vbYesNo)
If Confirmar = vbYes Then
Next_LibroDiario = WShe_LibroDiario.Cells(Rows.Count, 2).End(xlUp).Row + 1
If APP_RegistroContable.OptionButton_Débito = True Then
WShe_LibroDiario.Cells(Next_LibroDiario, 7) = APP_RegistroContable.Monto + 0
APP_RegistroContable.Monto = ""
ElseIf APP_RegistroContable.OptionButton_Crédito = True Then
WShe_LibroDiario.Cells(Next_LibroDiario, 8) = APP_RegistroContable.Monto + 0
APP_RegistroContable.Monto = ""
ElseIf APP_RegistroContable.OptionButton_Débito = False _
And APP_RegistroContable.OptionButton_Crédito = False _
Then
MsgBox "Please select an accounting item"
Exit Sub
End If
WShe_LibroDiario.Cells(Next_LibroDiario, 2) = APP_RegistroContable.Ctas_Bancarias
APP_RegistroContable.Ctas_Bancarias = ""
WShe_LibroDiario.Cells(Next_LibroDiario, 3) = CDate(APP_RegistroContable.Fecha)
APP_RegistroContable.Fecha = ""
WShe_LibroDiario.Cells(Next_LibroDiario, 4) = APP_RegistroContable.Recibo_CF
APP_RegistroContable.Recibo_CF = ""
WShe_LibroDiario.Cells(Next_LibroDiario, 5) = APP_RegistroContable.Nombre
APP_RegistroContable.Nombre = ""
WShe_LibroDiario.Cells(Next_LibroDiario, 6) = APP_RegistroContable.Auxiliar + 0
WShe_LibroDiario.Cells(Next_LibroDiario, 9) = APP_RegistroContable.Clasificación
APP_RegistroContable.Clasificación = ""
WShe_LibroDiario.Cells(Next_LibroDiario, 10) = APP_RegistroContable.Comentario
APP_RegistroContable.Comentario = ""
' This part creates an ID for the accounting operation using the date registered and the number of
' operations registered in that date
Last_ID = WShe_LibroDiario.Cells(Rows.Count, 2).End(xlUp).Row
Set Rang_Fecha = WShe_LibroDiario.Range("C8:C" & Last_ID)
Set Rang_ID = WShe_LibroDiario.Cells(Last_ID, 3)
Inte_IDGenerator = WorksheetFunction.CountIf(Rang_Fecha, Rang_ID)
WShe_LibroDiario.Cells(Last_ID, 1).Value = WShe_LibroDiario.Cells(Last_ID, 3).Value & "-0" & _
Inte_IDGenerator
MsgBox "The accounting operation is now in the system"
End if
Related
I have a form with two different listboxes. One for downtime data and one for production data. I can add new data and delete data via both listboxes. I can edit a selected row as well. The problem I'm running into is that after I edit and update a row for the production listbox and then enter in new data for new row it keeps putting that data in the last row I edited. If I don't edit a row then anytime I add new data it automatically goes to the next row. This doesn't happen with the downtime section, only the production section. With the downtime section everything works as it should. Attached is the workbook. Any help is greatly appreciated.
This is the code to update the listbox with what was entered into the text boxes above the listbox.
Sub Prod_Submit()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("ADHData")
If MainForm.txtRowNumberProd.Value = "" Then
iRow = [Counta(ADHData!A:A)] + 1
Else
iRow = MainForm.txtRowNumberProd.Value
End If
With sh
.Cells(iRow, 1) = MainForm.OrderA.Value
.Cells(iRow, 2) = MainForm.StockA.Value
.Cells(iRow, 3) = MainForm.FaceA.Value
.Cells(iRow, 4) = MainForm.LinerA.Value
.Cells(iRow, 5) = MainForm.WidthA.Value
.Cells(iRow, 6) = MainForm.PrevContA.Value
.Cells(iRow, 7) = MainForm.ContA.Value
.Cells(iRow, 8) = MainForm.PrevGoodA.Value
.Cells(iRow, 9) = MainForm.GoodA.Value
End With
End Sub
This is my code for selecting the row that needs to be edited
Private Sub CommandButton2_Click()
If Select_Prod = 0 Then
MsgBox "No row is selected.", vbOKOnly + vbInformation, "Edit"
Exit Sub
End If
MainForm.txtRowNumberProd.Value = Select_Prod + 1
MainForm.OrderA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 0)
MainForm.StockA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 1)
MainForm.FaceA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 2)
MainForm.LinerA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 3)
MainForm.WidthA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 4)
MainForm.PrevContA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 5)
MainForm.ContA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 6)
MainForm.PrevGoodA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 7)
MainForm.GoodA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 8)
MsgBox "Please make the required changes and update the new production data.", vbOKOnly + vbInformation, "Edit"
End Sub
And this is my Select_Prod Code
Function Select_Prod() As Long
Dim i As Long
Select_Prod = 0
For i = 0 To MainForm.Production_TableA.ListCount - 1
If MainForm.Production_TableA.Selected(i) = True Then
Select_Prod = i + 1
Exit For
End If
Next i
End Function
And my code to reset the textboxes
Sub Prod_Reset()
Dim iRow As Long
iRow = [Counta(ADHData!A:A)] + 1 ' idetifying the last row
With MainForm
MainForm.OrderA.Value = ""
MainForm.StockA.Value = ""
MainForm.FaceA.Value = ""
MainForm.LinerA.Value = ""
MainForm.WidthA.Value = ""
MainForm.PrevContA.Value = ""
MainForm.ContA.Value = ""
MainForm.PrevGoodA.Value = ""
MainForm.GoodA.Value = ""
.Production_TableA.ColumnCount = 9
.Production_TableA.ColumnHeads = True
.Production_TableA.ColumnWidths = "55,55,70,71,50,106,77,69,42"
If iRow > 1 Then
.Production_TableA.RowSource = "ADHData!A2:J" & iRow
Else
.Production_TableA.RowSource = "ADHData!A2:J21"
End If
End With
End Sub
So I made an excel sheet with a button to add/remove stock and add a new line if the stock you entered isn't in the system yet. This was done through a combo box. I have a line which pastes the combo box value (for when a new item is added) and essentially duplicated this in another cell but for some reason it's sending me an application or object error.
Dim C As Range
With lstRng
Set C = .Find(cbxList.Value, LookIn:=xlValues)
If C Is Nothing Then
Range("a65536").End(xlUp).Offset(1, 0).Value = cbxList.Value #this one works and adds to the end of my stock list
Range("b65536").End(xlUp).Offset(1, 0).Value = tbxStock.Value
Range("aa65536").End(xlUp).Offset(1, 0).Value = "Stock in"
Range("ab65536").End(x1Up).Offset(1, 0).Value = cbxList.Value
Range("ac65536").End(xlUp).Offset(1, 0).Value = tbxStock.Value
Range("ad65536").End(xlUp).Offset(1, 0).Value = txtDate.Value
Range("ae65536").End(xlUp).Offset(1, 0).Value = txtRequest.Value
Range("af65536").End(xlUp).Offset(1, 0).Value = txtAllocate.Value
Range("ag65536").End(xlUp).Offset(1, 0).Value = txtReason.Value
Me.cbxList.Value = ""
Me.tbxStock.Value = ""
Me.txtDate.Value = ""
Me.txtRequest.Value = ""
Me.txtAllocate.Value = ""
Me.txtReason.Value = ""
ElseIf Not C Is Nothing Then
C.Offset(0, 1).Value = C.Offset(0, 1).Value + tbxStock.Value
Range("aa65536").End(xlUp).Offset(1, 0).Value = "Stock in"
Range("ab65536").End(x1Up).Offset(1, 0).Value = cbxList.Value #the error is here for this piece. If I mouse over the "cbxList.Value" it shows me the value I entered and if I mouse over the previous bit it gives me - = <Application-defined or Object-defined error>
Range("ac65536").End(xlUp).Offset(1, 0).Value = tbxStock.Value
Range("ad65536").End(xlUp).Offset(1, 0).Value = txtDate.Value
Range("ae65536").End(xlUp).Offset(1, 0).Value = txtRequest.Value
Range("af65536").End(xlUp).Offset(1, 0).Value = txtAllocate.Value
Range("ag65536").End(xlUp).Offset(1, 0).Value = txtReason.Value
End If
End With
Me.cbxList.Value = ""
Me.tbxStock.Value = ""
Me.txtDate.Value = ""
Me.txtRequest.Value = ""
Me.txtAllocate.Value = ""
Me.txtReason.Value = ""
End Sub
Hi Im having a problem on Updating and Deleting the data on my Worksheet. Using VBA Excel user form I always got a problem on Application defined object defined error.
I tried Rows select method but I cant get the output that I needed.
Private Sub cmdUpdate_Click()
If Me.cmbAssetTag.Value = "" Then
MsgBox "Asset Tag Can Not be Blank!!!", vbExclamation, "Asset Tag"
Exit Sub
End If
AssetTag = Me.cmbAssetTag.Value
Sheets("Assets").Select
Dim r As Single
Dim msg As String
Dim ans As String
r = Me.cmbAssetTag.Value
Rows(r, Cells).Select
Cells(r, 2) = Me.txtName.Text
Cells(r, 3) = Me.txtManager.Text
Cells(r, 4) = Me.txtDepartment.Text
Cells(r, 5) = Me.txtAction.Text
Cells(r, 6) = Me.txtTemplate.Text
Cells(r, 7) = Me.txtModel.Text
Cells(r, 8) = Me.txtReason.Text
Cells(r, 9) = Me.txtDate.Text
Cells(r, 10) = Me.txtUpdatedBy.Text
msg = "Asset Tag" & rowselect & " Successfully Updated...Continue?"
Unload Me
ans = MsgBox(msg, vbYesNo, "Update")
If ans = vbYes Then
UserForm1.Show
Else
Sheets("Assets").Select
End If
End Sub
The actual result should replaced the data on the sheet with the replaced input
Essentially, I want to insert a timestamp for each row in column A if any other cells in that row are NOT blank. I want this to executive under my Sub PASTE() all at once.
I have a sub running which executives pasting specifics values to from columns to B:K on each row. I'd like this to finish running and then have it insert the timestamp for when it finished it column A. This way I can keep track of my analysis results, paste them in a worksheet and then timestamp them.
Sub PASTE()
erw = Sheet8.Cells(1, 1).CurrentRegion.Rows.Count + 1
If Len(Range("D50")) <> 0 Then
Sheet8.Cells(erw, 2) = Sheet2.Range("D50")
Sheet8.Cells(erw, 3) = Sheet2.Range("D51")
Sheet8.Cells(erw, 4) = Sheet2.Range("D52")
Sheet8.Cells(erw, 5) = Sheet2.Range("D53")
Sheet8.Cells(erw, 6) = Sheet2.Range("D54")
Sheet8.Cells(erw, 7) = Sheet2.Range("D55")
Sheet8.Cells(erw, 8) = Sheet2.Range("D56")
Sheet8.Cells(erw, 9) = Sheet2.Range("D57")
Sheet8.Cells(erw, 10) = Sheet2.Range("D58")
Sheet8.Cells(erw, 11) = Sheet2.Range("D59")
Sheet8.Cells(erw, 12) = Sheet2.Range("D60")
Sheet8.Cells(erw, 13) = Sheet2.Range("D61")
Sheet2.Range("D50") = ""
Sheet2.Range("D51") = ""
Sheet2.Range("D52") = ""
Sheet2.Range("D53") = ""
Sheet2.Range("D54") = ""
Sheet2.Range("D55") = ""
Sheet2.Range("D56") = ""
Sheet2.Range("D57") = ""
Sheet2.Range("D58") = ""
Sheet2.Range("D59") = ""
Sheet2.Range("D60") = ""
Sheet2.Range("D61") = ""
Else
MsgBox "You must enter the values"
End If
End Sub
I am basically trying to create a report for my larger scale macro. The report will show each mail processsed and what attachments are found within the email.
I have the following code working, but does not supply me with the correct results for the .csv files only. Can anyone see any problems that I cannot?
If .Attachments.Count = 0 Then
csv_report = "NO"
pdf_report = "NO"
xls_report = "NO"
End If
If .Attachments.Count > 0 Then
For i2 = 1 To .Attachments.Count
If LCase(Right(.Attachments(i2).Filename, 4)) = ".csv" Then
csv_report = "YES"
Else
csv_report = "NO"
End If
If LCase(Right(.Attachments(i2).Filename, 4)) = ".pdf" Then
pdf_report = "YES"
Else
pdf_report = "NO"
End If
If LCase(Right(.Attachments(i2).Filename, 4)) = ".xls" Or LCase(Right(.Attachments(i2).Filename, 5)) = ".xlsx" Then
xls_report = "YES"
Else
xls_report = "NO"
End If
Next
End If
Sheets("Mail Report").Activate
Range("C65000").End(xlUp).Offset(1).Value = csv_report
Range("D65000").End(xlUp).Offset(1).Value = pdf_report
Range("E65000").End(xlUp).Offset(1).Value = xls_report
subject_line = mail.Subject
Range("A65000").End(xlUp).Offset(1).Value = subject_line
So by just adding 'GoTo' function I was able to answer my own query. Thank you all for leaving comments
If .Attachments.Count = 0 Then
csv_report = "NO"
pdf_report = "NO"
xls_report = "NO"
End If
If .Attachments.Count > 0 Then
For i2 = 1 To .Attachments.Count
If LCase(Right(.Attachments(i2).Filename, 4)) = ".csv" Then
csv_report = "YES"
GoTo CSVyes 'if a .csv file is found, it skips to the PDF attachment checker
Else
csv_report = "NO"
End If
Next
CSVyes:
For i2 = 1 To .Attachments.Count
If LCase(Right(.Attachments(i2).Filename, 4)) = ".pdf" Then
pdf_report = "YES"
GoTo PDFyes 'if a .pdf file is found, it skips to the XLS attachment checker
Else
pdf_report = "NO"
End If
Next
PDFyes:
For i2 = 1 To .Attachments.Count
If LCase(Right(.Attachments(i2).Filename, 4)) = ".xls" Or LCase(Right(.Attachments(i2).Filename, 5)) = ".xlsx" Or UCase(Right(.Attachments(i2).Filename, 4)) = ".XLS" Then
xls_report = "YES"
GoTo XLSyes 'if a .xls file is found, it skips to the end of the checks
Else
xls_report = "NO"
End If
Next
XLSyes:
End If
Sheets("Mail Report").Activate
Range("C65000").End(xlUp).Offset(1).Value = csv_report
Range("D65000").End(xlUp).Offset(1).Value = pdf_report
Range("E65000").End(xlUp).Offset(1).Value = xls_report
subject_line = mail.Subject
Range("A65000").End(xlUp).Offset(1).Value = subject_line