VBA to repeat recording data

AbdelrahmanExcel

New Member
Joined
Dec 24, 2024
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
Dears
i am creating simple task tracker to add task with due dates
some times one of team member has assigned task with fixed frequency such as every day , every week ...etc
i am trying to make macro code to write the frequency period and type required , and the excel automatically add tasks according to assigned period
i have tried this code but not work
Kindly support
VBA Code:
Sub Task_MakeRecurring()
Dim Freq As Long
Dim FreqQty As Long
Dim TotTime As Double
Dim StartOnDt As Date, UntilDt As Date, StartDt As Date, EndDt As Date
With Main
    'If .Range("b5").Value = Empty Then
        'MsgBox "Please make sure to enter a Task Name before saving"
        'Exit Sub
    'End If
    'If .Range("b7").Value = Empty Or .Range("b8").Value = Empty Then
       ' MsgBox "Please make sure task has Start and End Dates to make them recurring"
       ' Exit Sub
   ' End If
   ' If .Range("B1").Value < 4 Then
        'MsgBox "Please make sure to enter Recurring Frequency, Start On and Until Date fields to make this task Recurring"
      '  Exit Sub
   ' End If
    TotTime = .Range("g2").Value 'Total Time
    FreqQty = .Range("b14").Value 'Frequency Qty
    Freq = .Range("b13").Value 'Frequency
    StartOnDt = .Range("b15").Value 'Start On Date
    UntilDt = .Range("b16").Value 'Until Date
    
    StartDt = StartOnDt  'Set Initial Starting Date
    EndDt = StartDt + TotTime 'End Date is Start Date + Total Time
    
    Do While StartDt <= UntilDt 'Create Tasks Until Start Date is greater than Until Date
        .Range("b7").Value = StartDt 'Set Starting Date
        .Range("b8").Value = Int(EndDt)  'Set Ending Date (date as a whole number)
       Call Add_Data 'Save Task
        
        'Update Start & End Dates for Next Task
        Select Case Freq
            Case Is = "Day(s)"
                StartDt = DateAdd("d", FreqQty, StartDt)
          
            Case Is = "Week(s)"
                StartDt = DateAdd("ww", FreqQty, StartDt)
            Case Is = "Months(s)"
                StartDt = DateAdd("m", FreqQty, StartDt)
        End Select
            EndDt = StartDt + TotTime 'Update End Date
    Loop
End With
Call Add_Data 'Update Task list
End Sub


1735070096435.png
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the Board!

You seem to be showing us your input form and VBA code that pulls the data from that form, but have not shown us what your desired output should look like.
Where do you want this data written? Can you show us some sample expected output?
 
Upvote 0

Forum statistics

Threads
1,225,073
Messages
6,182,707
Members
453,132
Latest member
nsnodgrass73

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