VBA Auto Fill Table with all the dates within a date range with inputed data.

Status
Not open for further replies.

Nathan95

New Member
Joined
Mar 1, 2020
Messages
34
Office Version
  1. 2010
Platform
  1. Windows
Hey All,

Im pretty new too VBA so I have no clue on how to go about in doing this, But what Im looking to do is work on a leave tracker, where someone can input the start and end date range for the leave as well as what the leave type is and their Employee number (P Number). Then when they click the "Input Leave" Button I want it to auto fill in a table with each date within that date range to have a seperate row with the same Leave type and employee number that was entered.

Any help would be appreciated :)
 
If you mean the date just as a number like in your earlier image, then try adding this line

Rich (BB code):
Sub Enter_Data()
  Dim FirstDate As Date, LastDate As Date
  Dim rBlanks As Range
 
  On Error Resume Next
  Set rBlanks = Range("K7,M7,K9,N9").SpecialCells(xlBlanks)
  On Error GoTo 0
  If rBlanks Is Nothing Then
    FirstDate = Range("K7").Value
    LastDate = Range("N7").Value
    With Range("D" & Rows.Count).End(xlUp).Offset(1).Resize(LastDate - FirstDate + 1)
      .Value = Evaluate("Row(" & CLng(FirstDate) & ":" & CLng(LastDate) & ")")
      .NumberFormat = "dd-mmm-yy"
      .Offset(, 1).Value = Range("N9").Value
      .Offset(, -2).Value = Range("K9").Value
      .Offset(, -3).Value = Evaluate(.Offset(, -2).Address & "&" & .Address)
    End With
  Else
    MsgBox "Data missing"
  End If
End Sub
Hey Peter,

Another quick one, So i ended up using a user form and everything works perfectly. The only issue is to select the start and end date I called upon the Calendar Function in VBA, which works fine on my pc, However if i send the file to another user, since they don't have the calendar function enabled the calendar does not populate and instead they just get a black form (inplace of the calendar).

Is there a way to automatically call upon and assign the calendar function to each user when they press the button (at the start of the code) that way the calendar will appear for them?
 

Attachments

  • Capture.JPG
    Capture.JPG
    47.4 KB · Views: 4
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Another quick one,
I normally fear "quick one" questions as they are often far from that. :eek:
However, in this case it is a quick one for me: Your question is not in my 'strong point' fields so I am not going to attempt to answer.

Since this is quite a different question to the original, I suggest that you start a new thread about this issue.
If you do, post back here with a link to the new thread. At that point I will lock this thread so we don't have more than one thread with the same question.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

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