prevent message box from copying from userform to sheet based on matching missed month.

Ali M

Active Member
Joined
Oct 10, 2021
Messages
359
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi,
I have code to copy data from userform to SS sheet, but what I want show message box if I have missed month are not copied in FORM sheet and don't copy from form to SS sheet .
so on userform I suppose the current month is MAR as filled on form showing picture . and there are missed months in FORM sheet in this case I would match dates in textbox1,textbox2 with column A in FORM sheet so will be FEB is missed then should show message inform me how many missed months and their names " you have one missed month is FEB, so you should adjustment this problem" after message is gone then should not copy data from userform to SS sheet.
q1.JPG





the code copy like this
al.xlsm
ABCD
1FROM DATETO DATENAMEFIRST BALANCE
201/01/202531/01/2025ALI-3,000.00
3SALARY2,000.00
4AMOUNT-1,000.00
5
6
7FROM DATETO DATENAMEFIRST BALANCE
801/01/202531/01/2025ALILA2,000.00
9SALARY1,000.00
10AMOUNT3,000.00
SS



here is code
VBA Code:
Private Sub CommandButton1_Click()
Dim Fnd As Range, Nxt As Long
With Sheets("SS")
    Nxt = .Cells(.Rows.Count, 3).End(xlUp).Row + 2
    If Nxt = 2 Then Nxt = 1
    Set Fnd = .Range("C:C").Find(TextBox3, , xlValues, xlWhole)
    If Not Fnd Is Nothing Then Nxt = Fnd.Row - 1
    With .Cells(Nxt, 1).Resize(, 4)
        .Value = Array(Label1, Label2, Label3, Label4)
        .Interior.Color = RGB(255, 102, 0)
    End With
    .Cells(Nxt + 1, 1).Resize(, 4) = Array(TextBox1, TextBox2, TextBox3, TextBox4.Value)
    .Cells(Nxt + 2, 3).Resize(, 2) = Array(Label6, TextBox5.Value)
    .Cells(Nxt + 3, 3).Resize(, 2) = Array(Label5, TextBox6.Value)
    .Cells(Nxt + 2, 3).Resize(2).Interior.Color = RGB(255, 102, 0)
    .Cells(Nxt, 1).Resize(2, 4).Borders.Weight = 2
    .Cells(Nxt + 2, 3).Resize(2, 2).Borders.Weight = 2
   
End With
End Sub
and I want preventing to copy from form to SS sheet after show message.
and this sheet to match textbox1,textbox2 with column A
al.xlsm
ABCD
1MONTHITEMNAMEBALANCE
2Jan-251ALI2,000.00
32ALILA1,000.00
4TOTAL-9,000.00
FORM

if there is no missed months then should copy from form to SS sheet.
last thing if I try date in TB1,TB2 and month is existed in FORM sheet then show message " this month is already existed and clear TB1,TB2 after message is gone .



thanks.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,226,050
Messages
6,188,585
Members
453,485
Latest member
SBO89

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