Step1 Create a List on sheet 2 Cells A1:A11 |
Step 2 On Sheet 1 Put the Dropdownlist in Cell C1 |
Named ranges using formula’s
The Dynamic Drop down list is activated by Worksheet “On Change“ command VBA editor Sheet1. Which controls the macro Empl_Load.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("F2")) Is Nothing Then
If Range("F2").Value <> Empty And Range("B5").Value <> Empty Then Empl_Load
‘This “if” command controls macro Empl_Load
End If
End Sub
The EMPL_Load Macro (this uses row 1 sheet2 as mapped locations
Sub Empl_Load()
Dim EmpRow As Long
Dim EmpCol As Long
With Sheet1
If .Range("B5").Value = Empty Then
MsgBox "Please enter a valid Employee from the dropdown List"
Exit Sub
End If
.Range("B1").Value = True
EmpRow = .Range("B5").Value ‘ Study this as it is what puts the data in the correct place
For EmpCol = 1 To 28
.Range(Sheet2.Cells(1, EmpCol).Value).Value = Sheet2.Cells(EmpRow, EmpCol).Value
Next EmpCol
.Range("B1").Value = False
End With
End Sub
Lets look at this more closely
EmpRow = .Range("B5").Value ‘ So EmpRow becomes Row "4" on Sheet2
For EmpCol = 1 To 28 ' This will cycle through 28 columns
.Range(Sheet2.Cells(1, EmpCol).Value).Value = Sheet2.Cells(EmpRow, EmpCol).Value ' Lets look at this broken into 2 parts
Part1 - The Destination Cell will become cell "J2"
.Range(Sheet2.Cells(1,EmpCol).Value).Value)
would = Sheet2 cells(1 or Row 1, EmpCol or Col 1).Value which is "J2" See cell "A1" above. "J2" is Employee ID
Part 2 - So "J2" will be filled with the Value in Cells(EmpRow,EmpCol)
=Sheet2.Cells(EmpRow, EmpCol).Value 'The contents in Sheet2.Cells(4,1).Value
EmpRow = Cell B5 on sheet1 which is 4
EmpCol = 1 and will change for each column because EmpCol = 1 to 28
Next EmpCol
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("E4:J4")) Is Nothing Then ' This makes each horizontal cell in the range a target button
Range("B2").Value = Target.Column ' The target column numberis placed in cell B2 - So Column "E" is the 5th column noted in cell B2
Range("F2").Select
switchHorizontialTabs ' This is the macro that will run and control what is seen on screen
End If
If Not Intersect(Target, Range("E66:E129")) Is Nothing Then ' This is for the Vertical tabs not seen in the picture above
If Target.Value = Empty Or Target.Value = "Select Option" Then Exit Sub
SwitchVerticalTabs
End If
End Sub
Sub switchHorizontialTabs()
Dim SelCol As Long
Dim FirstRow As Long
With Sheet1
SelCol = Range("B2").Value ' SelCol is 5 because cell B2 is 5 which was created by the Target statement above
.Range("5:144").EntireRow.Hidden = True ' This Hides all rows
FirstRow = 5 + ((SelCol - 5) * 20) ' This calculates the First Row and names it "FirstRow"
.Range(FirstRow & ":" & FirstRow + 19).EntireRow.Hidden = False 'This defines the range to unhide. FirstRow = 5 Thru FirstRow +19 or 24 (5:24)
End With
End Sub
Sub SwitchVerticalTabs()
Dim SelRow As Long
Dim FirstRow As Long
SelRow = Right(ActiveCell.Row, 1) - 5
With Sheet1
.Range("65:144").EntireRow.Hidden = True
FirstRow = 65 + ((SelRow - 1) * 20)
.Range(FirstRow & ":" & FirstRow + 19).EntireRow.Hidden = False
.Range("B3").Value = SelRow + FirstRow
.Range("F2").Select
End With
End Sub
Formula is: =MOD(Row(),2)=0
Tthen Choose Color and Boarders Text,Text Color and so forth.
Sub CreatePDFForms()
Dim PDFTemplateFile, NewPDFName, SavePDFFolder, LastName As String
Dim ApptDate As Date
Dim CustRow, LastRow As Long
With Sheet1
If .Range("G18").Value = Empty Or .Range("G20").Value = Empty Then
MsgBox "Both PDF Template and Saved PDF Locations are required for macro to run"
Exit Sub
End If
LastRow = .Range("E9999").End(xlUp).Row 'Last Row
PDFTemplateFile = .Range("G18").Value 'Template File Name
SavePDFFolder = .Range("G20").Value 'Save PDF Folder
ThisWorkbook.FollowHyperlink PDFTemplateFile
Application.Wait Now + 0.00006
For CustRow = 5 To LastRow
LastName = .Range("E" & CustRow).Value 'Last Name
ApptDate = .Range("G" & CustRow).Value 'Appt Date
Application.SendKeys "{Tab}", True
Application.SendKeys LastName, True
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("F" & CustRow).Value, True 'First Name
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("I" & CustRow).Value, True 'Address
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("J" & CustRow).Value, True 'City
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("K" & CustRow).Value, True 'State
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("L" & CustRow).Value, True 'Zip
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("M" & CustRow).Value, True 'Email
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys "{Tab}", True
Application.SendKeys Format(.Range("N" & CustRow).Value, "###-###-####"), True 'Phone
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys "^(p)", True
Application.Wait Now + 0.00003
Application.SendKeys "{Enter}", True
Application.Wait Now + 0.00007
If Dir(SavePDFFolder & "\" & LastName & "_" & Format(ApptDate, "DD_MM_YYYY") & ".pdf") <> Empty Then Kill (SavePDFFolder & "\" & LastName & "_" & Format(ApptDate, "DD_MM_YYYY") & ".pdf")
Application.SendKeys "%(n)", True
Application.Wait Now + 0.00002
Application.SendKeys SavePDFFolder & "\" & LastName & "_" & Format(ApptDate, "DD_MM_YYYY") & ".pdf"
Application.Wait Now + 0.00003
Application.SendKeys "%(s)", True
Application.Wait Now + 0.00002
Next CustRow
Application.SendKeys "^(q)", True
Application.SendKeys "{numlock}%s", True
End With
End Sub