Hi Guys! Need your help again!
I need a code to make my userform write information in a table on another worksheet. Right now, my code is making it write the information on the next avalable row, which is usualy inside the table, but for some reason sometime the date gets entered several row after the table, which causes a lot of problem.
Here is the code I'm using so far ;
To be honest, I do not understand the code I'm using very well. I copied it from another worksheet that was doing something similar but I have no idea how to fix my problem. I know the code should refer to the table at some point, but unsure on how to achieve this. The ''dim'' and irow things confuses me a lot.
Thank you!
I need a code to make my userform write information in a table on another worksheet. Right now, my code is making it write the information on the next avalable row, which is usualy inside the table, but for some reason sometime the date gets entered several row after the table, which causes a lot of problem.
Here is the code I'm using so far ;
VBA Code:
Private Sub CommandButton1_Click()
If Trim(TextBox3.Value) = "" Or Trim(TextBox5.Value) = "" Or Trim(TextBox6.Value) = "" Then
MsgBox "Informations manquantes!" & vbCrLf & " " & " " & vbCrLf & "Les champs en jaune sont obligatoires", vbCritical, "Erreur"
Cancel = True
Exit Sub
Else
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Panier")
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
With ws
.Cells(iRow, 1).Value = "En attente"
.Cells(iRow, 2).Value = "Non assigné"
.Cells(iRow, 3).Value = Me.TextBox1.Value
.Cells(iRow, 4).Value = Me.TextBox6.Value
.Cells(iRow, 5).Value = Me.TextBox2.Value
.Cells(iRow, 6).Value = Me.TextBox3.Value
.Cells(iRow, 7).Value = Me.TextBox4.Value
.Cells(iRow, 8).Value = Me.TextBox5.Value
.Cells(iRow, 9).Value = Me.TextBox8.Value
.Cells(iRow, 10).Value = Me.TextBox7.Value
.Cells(iRow, 11).Value = Format(Now, "dd-mm-yyyy")
End With
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
Unload Me
Save
ActiveWorkbook.Worksheets("Panier").ListObjects("Panier").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Panier").ListObjects("Panier").Sort.SortFields.Add _
Key:=Range("Panier[[#All],[Requis Le]]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Panier").ListObjects("Panier").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
MsgBox "Demande envoyée!" & vbCrLf & " " & " " & vbCrLf & "Fermeture de l'application"
For Each w In Application.Workbooks
w.Save
Next w
Application.Quit
End If
End Sub
To be honest, I do not understand the code I'm using very well. I copied it from another worksheet that was doing something similar but I have no idea how to fix my problem. I know the code should refer to the table at some point, but unsure on how to achieve this. The ''dim'' and irow things confuses me a lot.
Thank you!