this code transposes all your data from "Data" into a new tab called "New Data" and then pulls the dates listed into a validation list in A1 of the tab Today.
Sub transpose_data()
Dim output As Worksheet
Dim inpt As Worksheet
Dim rng As Range
Dim lr As Long
Dim nlr As Long
Dim daterng As Long
Dim lc As Long
Dim nc As Long
Dim nr As Long
Dim searchdte As Date
Dim form_strng As String
On Error Resume Next
Set output = Sheets("New Data")
If output Is Nothing Then
Sheets.Add(, Sheets(Sheets.Count)).Name = "New Data"
Set output = Sheets("New Data")
End If
Set inpt = Sheets("Data")
lr = inpt.Range("A" & Rows.Count).End(3).Row
output.UsedRange.ClearContents
output.Range("A1").Value = "Date"
For Each rng In inpt.Range("A1:A" & lr)
If rng.Value = "EMP Name" Then
daterng = rng.Row
For i = 2 To 8
nlr = output.Range("A" & Rows.Count).End(3).Row + 1
output.Cells(nlr, 1).Formula = inpt.Cells(rng.Row, i).Formula
Next i
Else
lc = output.Cells(1, Columns.Count).End(xlToLeft).Column
If output.Range("A1:" & Cells(1, lc).Address).Find(rng.Value) Is Nothing Then
output.Cells(1, lc + 1) = rng.Value
lc = lc + 1
End If
nc = output.Range("A1:" & Cells(1, lc).Address).Find(rng.Value).Column
On Error Resume Next
For i = 2 To 8
searchdte = inpt.Cells(daterng, i).Value
nr = output.Range("A1:A" & nlr).Find(searchdte).Row
output.Cells(nr, nc).Value = rng.Offset(0, i - 1).Value
Next i
End If
Next rng
form_strng = "='New Data'!$A$2:$A$" & nlr - 1
With Sheets("Today").Range("A1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=form_strng
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
it should be easier from here to pull in your shift information but i hit a snag there since all your information is text - i don't know a way off the top of my head to see how many people are working on a given day using formulas... it should be doable with some more vba, or if you are ok to just include all of your employee names (returning "OFF" or w/e for those employees who are not working you could use a pretty simple hlookup(match())
like:
Formula:
=HLOOKUP(A3,'New Data'!$A$1:$F$23,MATCH(Today!$A$1,'New Data'!$A$1:$A$23,0),FALSE)
as in the attached.
i'm out for the weekend. will try to check back in on Monday - either way if you don't get a hit just reply again with something like "bump no response" or w/e to push this thread back to the top of what's new and someone else should be able to help you out.
Bookmarks