VB add new row with unique date by candidate id

Magoosball

Board Regular
Joined
Jun 4, 2017
Messages
70
Office Version
  1. 365
Hi

I'm trying to write a VB script that states from row 2 to last row; if the sales number (Column C) is greater than 10 then create a new row at the bottom of the data set with the same candidate ID, a date that isn't currently tied to that employee number and the sales number minus 10.

The Date should be a Date from the previous work week (Sunday through Saturday so currently 6/30/2019 - 7/6/2019) that doesn't currently exist for this employee. If the candidate happens to already have 7 rows of data for each day of the week the date should report back as "ERRORR - Each Date already exists for this candidate".

The data set below would be a sample starting data set. For example: Candidate ID 12027 should have a new row inserted at the bottom of the data set. The Candidate id would be 12027. The date would be any date in the previous work week that isn't 6/30, 7/1, 7/2, 7/4, or 7/5 land the sales number would be 5. The 2nd row of data wouldn't need a new row added because the sales number is already less than 10. The third row would need a new row added. Candidate 18498 would have 1 new row entered at the bottom of the data set with a date that isn't 7/2/2019 and a sales number of 1.

Thank you in advance!

Candidate IDDateSales Number
120276/30/201915
120277/1/20199
120277/2/201911
120277/4/20196
120277/5/201917
184987/2/201911
18498
7/3/20192
104416/30/20196
131297/4/20199

<tbody>
</tbody>
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi

I'm trying to write a VB script that states from row 2 to last row; if the sales number (Column C) is greater than 10 then create a new row at the bottom of the data set with the same candidate ID, a date that isn't currently tied to that employee number and the sales number minus 10.

The Date should be a Date from the previous work week (Sunday through Saturday so currently 6/30/2019 - 7/6/2019) that doesn't currently exist for this employee. If the candidate happens to already have 7 rows of data for each day of the week the date should report back as "ERRORR - Each Date already exists for this candidate".

The data set below would be a sample starting data set. For example: Candidate ID 12027 should have a new row inserted at the bottom of the data set. The Candidate id would be 12027. The date would be any date in the previous work week that isn't 6/30, 7/1, 7/2, 7/4, or 7/5 land the sales number would be 5. The 2nd row of data wouldn't need a new row added because the sales number is already less than 10. The third row would need a new row added. Candidate 18498 would have 1 new row entered at the bottom of the data set with a date that isn't 7/2/2019 and a sales number of 1.

Thank you in advance!

Candidate IDDateSales Number
120276/30/201915
120277/1/20199
120277/2/201911
120277/4/20196
120277/5/201917
184987/2/201911
184987/3/20192
104416/30/20196
131297/4/20199

<tbody>
</tbody>

This should get you a good start. The date part will require significant code.

Code:
Sub HereWeGo()
    With Sheets("Sheet1")
        For r = 2 To .UsedRange.Rows.Count
            If Cells(r, 3) > 10 Then
                Cells(.UsedRange.Rows.Count + 1, 1) = Cells(r, 1)
                Cells(.UsedRange.Rows.Count, 2) = Cells(r, 2)   'I simply do not have the time today at work to finish this part.
                Cells(.UsedRange.Rows.Count, 3) = CInt(Cells(r, 3)) - 10
            End If
        Next r
    End With
End Sub
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,214,815
Messages
6,121,715
Members
449,049
Latest member
THMarana

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