Auto Insert Row With Predictive Data

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
I am in desperate need of some assistance. I'm trying to teach myself VBA in Excel 2010 and am building an application for a friend. I've come to a point where I'm at a standstill until I can figure this piece out. I've posted this question a couple of times and haven't received any responses, so I'm hoping that if I change the question around a little bit, someone will be willing to assist.

The application tracks several things for her business, where she currently has 30 Clients. The difficult piece for me is tracking payments. As of now, I have everyone on one tab, updated via UserForms. What I'd like to have happen is for the application to "predict" when the next payment is due, and auto-insert a row and copies the data from the most recent entry, into a new row, adjusting the next payment due date.

In other words, a new row would be created using the data in row 3 (red font). All of the information present would be copied into the new row, except the DP Next Due value would say 11/04/17. Another new row would be created using the data in row 6 (red font), except the DP Next Due value would say 1/26/18.

Thoughts?


TodayUpdatedStatusFirstLastSuffixNameDP StatusDP StartDP Next DueDP AmtDP Pymt DateDP PaidDP Pymt StatusDP Freq
12/17/1710/24/17ActiveJennniferChuJennifer ChuActive09/04/1709/04/17$200.0009/04/17$200.00Paid TimelyM
12/17/1710/24/17ActiveJennniferChuJennifer ChuActive09/04/1709/04/17$200.0010/04/17$200.00Paid TimelyM
12/17/1710/24/17ActiveTomSmithJr.Tom Smith Jr.Active12/15/1712/15/17$200.0012/17/17$200.00Paid LateB
12/17/1710/24/17ActiveTomSmithJr.Tom Smith Jr.Active12/15/1712/29/17$250.00CurrentB
12/17/1711/30/17ActiveTomSmithJr.Tom Smith Jr.Active12/15/1701/12/18$250.00CurrentB

<colgroup><col span="2"><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 
Easiest option for part 1 is to have the sheets named the same as the client ID.
As for part 2, not quite sure what you mean. If your just pulling data from 1 sheet, why do you need to get the last row on multiple sheets?
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I think I have done the first part already. If the Client's Name is Rob Bowman and he's the first entry, his Client ID is RB1. Then Renee Bowman would be RB2 and so on. Is that what you're referring to? Easiest option for part 1 is to have the sheets named the same as the client ID.

As far as the LastRow, I would need that to ensure that the new records are being inserted at the bottom of the current data set, on each sheet. I suppose I could try and insert a row in row 2 and enter the data there, then sort the sheet.
 
Upvote 0
If the client ID is RB1 name the sheet RB1
To find the next row use something like this
Code:
   Dim NxtRw As Long
   NxtRw = Sheets("RB1").Range("A" & Rows.Count).End(xlUp).Offset(1)
 
Upvote 0
Is there a way to code for the next or last row, so that as new sheets are created, new code doesn't have to also be created?
 
Upvote 0
This will find the next row on whatever sheet you select from the combobox
Code:
   Dim Sht As String
   Dim NxtRw As Long
   
   Sht = Me.cobo_ClientID.Value
   NxtRw = Sheets(Sht).Range("A" & Rows.Count).End(xlUp).Offset(1).Row
   MsgBox NxtRw
 
Upvote 0
Ok...I'm completely lost. I'm not grasping the concept of how to code the scripting dictionary to read the correct sheet. Typically, all of the data is on one sheet, so I only have to reference that one sheet. With this task, I have to code for the User to select a Client ID on a form, that will then pull in the data from the sheet that has the same name as the Client ID. Example...Client ID = RB1, Sheet is named RB1. There are multiple entries on the RB1 Sheet, so the max Updated date should be leveraged. Is there a different concept that I should research, or a different approach I should take?
 
Upvote 0
You've got a dictionary that is populating a combobox, with the client ID, assuming that works, you can simply use the combobox value to refer to the sheet.
 
Upvote 0
The dictionary that I've been using is tied to a specific sheet, not the dynamic list of sheets that needs to be referenced. It also references a specific range on said sheet.
 
Upvote 0
Does that range contain a list of ALL client Ids?
 
Upvote 0
Yes it does, but it isn't tying to the max updated date on each unique sheet. Here it is.

Code:
Set coboDict = CreateObject("Scripting.Dictionary")With coboDict
    For Each cStatsClientID In ws1.Range("StatsClientID")
        If Not .exists(cStatsClientID.Value) Then
            .Add cStatsClientID.Value, cStatsClientID.Row
        Else
            If CLng(cStatsClientID.Offset(, -2).Value) > CLng(ws1.Range("B" & .Item(cStatsClientID.Value))) Then
            .Item(cStatsClientID.Value) = cStatsClientID.Row
            End If
        End If
    Next cStatsClientID
    Me.cobo_ClientID.List = Application.Transpose(.keys)
End With
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,668
Members
449,463
Latest member
Jojomen56

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