Hi,
I am beginner to vba code.
What I expecting in my code,
In Userform
Combo box = fetching Data Sheet values from Column A. This goes to next sheet range B2.
Delivery Name text box = fetching Data Sheet from Column D. This goes to next sheet range D2.
Date Text box = manually entering dates. This goes to next sheet range H2.
When Clicking Confirm button,
Checking in Data Sheet & coping combo box matched row values into next sheet from A3:L3. Here matched row titles will paste like item#1, Item#3, Item#4, etc. if items more than 10, show message box,
And matched rows Column B & C values in Order Form Sheet range A4 & B4, pasting rest values in respective item columns and remove blank cells.
Eg.
Date Sheet Values Sample,
Userform
Order Form Sheet Format Sample
Expected Output in Order Form Sheet,
My code is,
I know this code is not correct. But I dont know how to rectify this issue.
I invite experts look my sheet and give me a solution or a idea. I am stuck here so long.
Thanks
I am beginner to vba code.
What I expecting in my code,
In Userform
Combo box = fetching Data Sheet values from Column A. This goes to next sheet range B2.
Delivery Name text box = fetching Data Sheet from Column D. This goes to next sheet range D2.
Date Text box = manually entering dates. This goes to next sheet range H2.
When Clicking Confirm button,
Checking in Data Sheet & coping combo box matched row values into next sheet from A3:L3. Here matched row titles will paste like item#1, Item#3, Item#4, etc. if items more than 10, show message box,
And matched rows Column B & C values in Order Form Sheet range A4 & B4, pasting rest values in respective item columns and remove blank cells.
Eg.
Date Sheet Values Sample,
Copy with Criteria & Paste.xlsm | |||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | AA | AB | AC | AD | AE | AF | AG | AH | AI | AJ | AK | AL | AM | AN | AO | AP | AQ | AR | AS | AT | AU | AV | AW | AX | AY | |||
1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | Order No | Date | Time | Name | Item#1 | Item#2 | Item#3 | Item#4 | Item#5 | Item#6 | Item#7 | Item#8 | Item#9 | Item#10 | Item#11 | Item#12 | Item#13 | Item#14 | Item#15 | Item#16 | Item#17 | Item#18 | Item#19 | Item#20 | Item#21 | Item#22 | Item#23 | Item#24 | Item#25 | Item#26 | Item#27 | Item#28 | Item#29 | Item#30 | Item#31 | Item#32 | Item#33 | Item#34 | Item#35 | Item#36 | Item#37 | Item#38 | Item#39 | Item#40 | Item#41 | Item#42 | Item#43 | Item#44 | Item#45 | Item#46 | |||
5 | 1 | 04-Aug-22 | 10:36 AM | Sivakumar | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
6 | 5 | 06-Aug-22 | 2:00 PM | Ramkumar | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
7 | 3 | 15-Aug-22 | 1:55 PM | Vimal | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
8 | 4 | 25-Aug-22 | 6:15 PM | Mohankumar | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
9 | 5 | 30-Aug-22 | 9:25 AM | Ramkumar | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
10 | 4 | 04-Sep-22 | 8:56 PM | Mohankumar | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
11 | 3 | 06-Sep-22 | 2:44 PM | Vimal | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
12 | 6 | 15-Sep-22 | 3:25 PM | Murugan | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
13 | 3 | 25-Sep-22 | 4:35 PM | Vimal | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
14 | 4 | 04-Oct-22 | 12:12 PM | Mohankumar | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
15 | 3 | 09-Oct-22 | 4:28 AM | Vimal | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
16 | 7 | 14-Oct-22 | 5:55 AM | Savitha | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 7 | |||||||||||||||||||||||||||||||||||||||||
Data |
Cell Formulas | ||
---|---|---|
Range | Formula | |
AY5:AY16 | AY5 | =COUNT(E5:AX5) |
Userform
Order Form Sheet Format Sample
Copy with Criteria & Paste.xlsm | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | |||
1 | |||||||||||||||||
2 | Order No : | Name : | Date : | ||||||||||||||
3 | Date | Time | |||||||||||||||
4 | |||||||||||||||||
5 | |||||||||||||||||
6 | |||||||||||||||||
7 | |||||||||||||||||
8 | |||||||||||||||||
9 | |||||||||||||||||
10 | |||||||||||||||||
11 | |||||||||||||||||
12 | |||||||||||||||||
13 | |||||||||||||||||
14 | Total | ||||||||||||||||
15 | |||||||||||||||||
Order Form |
Cell Formulas | ||
---|---|---|
Range | Formula | |
C14:N14 | C14 | =IF(ISBLANK(C4:C13)="",SUM(C4:C13),"") |
Expected Output in Order Form Sheet,
Copy with Criteria & Paste.xlsm | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | |||
1 | |||||||||||||||||
2 | Order No : | 0005 | Name : | Ramkumar | Date : | 17-Oct-22 | |||||||||||
3 | Date | Time | Item#2 | Item#4 | Item#6 | Item#7 | Item#8 | Item#9 | Item#10 | Item#14 | Item#16 | Item#19 | Item#20 | Item#21 | |||
4 | 06-Aug-22 | 2:00 PM | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | ||||||||
5 | 30-Aug-22 | 9:25 AM | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | ||||||||
6 | |||||||||||||||||
7 | |||||||||||||||||
8 | |||||||||||||||||
9 | |||||||||||||||||
10 | |||||||||||||||||
11 | |||||||||||||||||
12 | |||||||||||||||||
13 | |||||||||||||||||
14 | Total | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 55.00 | 110.00 | 110.00 | 55.00 | 55.00 | 55.00 | 55.00 | ||||
15 | |||||||||||||||||
Order Form |
Cell Formulas | ||
---|---|---|
Range | Formula | |
C14:N14 | C14 | =IF(ISBLANK(C4:C13)=TRUE,"",SUM(C4:C13)) |
My code is,
VBA Code:
Private Sub cmdconfirmO_Click()
Dim ecol As Long, erow As Long, lastrow As Long, i As Long, lastcol As Long
lastrow = Worksheets("Data").Cells(Rows.Count, 1).End(xlUp).row
lastcol = Worksheets("Data").Cells(4, Columns.Count).End(xlToLeft).Column
For i = 4 To lastrow
For j = 2 To lastcol
Worksheets("Order Form").Cells(2, 2).Value = Format(Me.cbordnO.Text, "0000")
Worksheets("Order Form").Cells(2, 4).Value = Me.txtdelO.Value
Worksheets("Order Form").Cells(2, 8).Value = Me.txtdateO.Value
If Worksheets("Data").Cells(i + 1, 1).Value = Me.cbordnO.Text Then
If Worksheets("Data").Cells(i, j) <> "" Then
Worksheets("Data").Range(Cells(i, j), Cells(i, j)).Copy
Worksheets("Order Form").Activate
erow = Worksheets("Order Form").Cells(Rows.Count, 1).End(xlUp).row
ecol = Worksheets("Order Form").Cells(3, Columns.Count).End(xlToLeft).Offset(0, 1).Column
Worksheets("Order Form").Cells(3, ecol).Select
ActiveSheet.Paste Destination:=Worksheets("Order Form").Range(Cells(erow, ecol), Cells(erow, ecol))
Sheets("Data").Activate
End If
End If
Next j
Next i
Application.CutCopyMode = False
Me.cbordnO.Value = ""
Me.txtdateO.Value = ""
Me.Hide
End Sub
I know this code is not correct. But I dont know how to rectify this issue.
I invite experts look my sheet and give me a solution or a idea. I am stuck here so long.
Thanks