SouthernGent0327
New Member
- Joined
- Jan 30, 2021
- Messages
- 14
- Office Version
- 365
- Platform
- Windows
Good Evening,
This workbook is setup for a userform to enter PO information so it can be added to a dynamic PO log. Once logged the user will close the userform and select a comboBox value Yes or No to indicate whether or not this PO should be deducted from the monthly budget. That being said, if the user selects NO the entire row should be copied to the very next page in the workbook, which is also the very next month. This should happen via a Worksheet Selection_Change Event only if the comboBox value = No, if the user selects Yes other formulas will add the value to the total deductions so it should essentially be ignored by the loop. Also, the pages in this workbook are exactly the same, so the range for the second month will be the same as the first month C14:H14, which again dynamically updates depending on how many NO values are selected. I am having alot of trouble getting the code to find only NO values and dynamically copy the row C14:H14 to the very next available row in the next worksheet. Please see the attached code I have written
This code only copies the last two data points and virtually ignores the condition. It will copy Yes and No if they are mixed throughout the data set and I am not sure why this is happening. Please help me solve this problem. Thank you in advance for the help.
This workbook is setup for a userform to enter PO information so it can be added to a dynamic PO log. Once logged the user will close the userform and select a comboBox value Yes or No to indicate whether or not this PO should be deducted from the monthly budget. That being said, if the user selects NO the entire row should be copied to the very next page in the workbook, which is also the very next month. This should happen via a Worksheet Selection_Change Event only if the comboBox value = No, if the user selects Yes other formulas will add the value to the total deductions so it should essentially be ignored by the loop. Also, the pages in this workbook are exactly the same, so the range for the second month will be the same as the first month C14:H14, which again dynamically updates depending on how many NO values are selected. I am having alot of trouble getting the code to find only NO values and dynamically copy the row C14:H14 to the very next available row in the next worksheet. Please see the attached code I have written
VBA Code:
Sub Transfer()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lRow1 As Long
Dim lRow2 As Long
Dim i As Long
Dim Crit As Range
Set ws1 = ActiveSheet
Set ws2 = ActiveSheet.Next
lRow1 = ws1.Range("J" & Rows.Count).End(xlUp).Row
For i = 14 To lRow1
If ws1.Cells(i, 10).Value = "No" Then
ws1.Range("C" & i & ":H" & lRow1).Copy
ws2.Activate
lRow2 = ws2.Range("J" & Rows.Count).End(xlUp).Offset(1, 0).Row
ws2.Range("C14:H" & lRow2).PasteSpecial Paste:=xlPasteValues
End If
Next i
End Sub
This code only copies the last two data points and virtually ignores the condition. It will copy Yes and No if they are mixed throughout the data set and I am not sure why this is happening. Please help me solve this problem. Thank you in advance for the help.