Hi,
I am almost to my goal of completing this VBA code. There is just one thing that I cannot figure out. When I run this code:
I generate all of the files based on the correct naming convention. However, each file has the same information in it. Basically, the loop is going through the validation list and naming the files based on the values in the list. But the loop is NOT updating the formulas that update the values on the dashboard and copying and pasting those values to each new workbook that I am saving.
Can anyone see what I need to tweak to get this loop to copy and paste the worksheet after the validation list updates the values?
Thanks in advance for any help! (Sorry if the answer is obvious, I'm fairly new to VBA)
I am almost to my goal of completing this VBA code. There is just one thing that I cannot figure out. When I run this code:
VBA Code:
Sub DashboardToPDF()
Dim FolderName As String, fName As String
Dim inputRange As Range, r As Range, c As Range
Dim newWB As Workbook, currentWB As Workbook
Dim newS As Worksheet, currentS As Worksheet
Dim sNm As String
Application.ScreenUpdating = False
'''' Open file dialog and choose folder
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = True Then
FolderName = .SelectedItems(1) & "\"
Else
Exit Sub
End If
End With
'''' Location of DataValidation cell
Set r = Worksheets("Formatted Template").Range("A1")
'''' Get DataValidation values
Set inputRange = Evaluate(r.Validation.Formula1)
'''' Loop through DataValidation list
For Each c In inputRange
r.Value = c.Value
sNm = c.Value
fName = Application.VLookup(sNm, Sheet2.Range("A1:B50"), 2, 0)
'Copy the data you need
ActiveSheet.Range("A:O").Select
Selection.Copy
'Create a new file that will receive the data
Set newWB = Workbooks.Add
With newWB
Set newS = newWB.Sheets("Sheet1")
newS.Range("A1").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False
'Save in CSV
Application.DisplayAlerts = False
.SaveAs Filename:=FolderName & fName & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
End With
Next c
Application.ScreenUpdating = True
End Sub
I generate all of the files based on the correct naming convention. However, each file has the same information in it. Basically, the loop is going through the validation list and naming the files based on the values in the list. But the loop is NOT updating the formulas that update the values on the dashboard and copying and pasting those values to each new workbook that I am saving.
Can anyone see what I need to tweak to get this loop to copy and paste the worksheet after the validation list updates the values?
Thanks in advance for any help! (Sorry if the answer is obvious, I'm fairly new to VBA)