Dim ShtName As String
Dim NameOfFile As String
Dim fsoFSO
Private Sub Populate_Worksheet()
' This will be executed from a button on the "Ribbon" to create this workbook from the SDWIS-generated
' "Comprehensive Water System Report".
' What this sub does:
' if directory does not exist
' then
' create directory
' endif
' copy template worksheets to comprehensive_water_system_report workbook
' save file as CEI_PWSID_NAME_DATE.xlsm
' populate general info fields
' populate administrative contact fields (AC)
' populate designated operator contact fields (DO)
' populate operator contact fields (OP)
' populate system inventory
' loop
' facilities
' Facility flows
' endloop
WQCDdir = "c:\New Inspection Stuff\"
WQCD_Source_Workbook = WQCDdir & "San Survey Blank.xlsm"
On Error Resume Next
' turn off msgs to streamline creation process
Application.DisplayAlerts = False
'if target directory does not exist locally, then create it. Sort of housekeeping to
'create standard directory on each local machine
Set fsoFSO = CreateObject("Scripting.FileSystemObject")
If Dir(WQCDdir, vbDirectory) = "" Then
fsoFSO.createfolder (WQCDdir)
End If
If Dir(WQCDdir & "Reports", vbDirectory) = "" Then
fsoFSO.createfolder (WQCDdir & "Reports")
End If
' required name of file is :"CEI_{pwsid}_{Name of system}_date"
'A4 will always contain {pwsid and name of system} as 1 group
NameOfFile = Sheets("Comprehensive Water System Repo").Range("A4").Value
'Check if san survey worksheets are already in workbook.
' if so, get out, no need to re-add sheets
' if not, copy all worksheets from the blank workbook to this 'working' workbook
For Each sh In Worksheets
If sh.Name Like "System Overview" Then
nameTaken = True
Exit For
End If
Next
If nameTaken = False Then
Set wkb = ActiveWorkbook
With Workbooks.Open(Filename:=WQCD_Source_Workbook)
' copy all of the worksheets in the blank workbook
.Worksheets("SDWISInventory Master").Copy Before:=wkb.Worksheets(1)
.Worksheets("Lookup Tables").Copy Before:=wkb.Worksheets(1)
.Worksheets("Site Visit Summary").Copy Before:=wkb.Worksheets(1)
.Worksheets("Inventory Changes").Copy Before:=wkb.Worksheets(1)
.Worksheets("IY12 Deficiencies").Copy Before:=wkb.Worksheets(1)
.Worksheets("Storage").Copy Before:=wkb.Worksheets(1)
.Worksheets("Distribution").Copy Before:=wkb.Worksheets(1)
.Worksheets("Treatment").Copy Before:=wkb.Worksheets(1)
.Worksheets("Sources").Copy Before:=wkb.Worksheets(1)
.Worksheets("System Mgt, M&R, OP ").Copy Before:=wkb.Worksheets(1)
.Worksheets("System Overview").Copy Before:=wkb.Worksheets(1)
.Close SaveChanges:=False
End With
'Save the workbook with defined name
ActiveWorkbook.SaveAs Filename:=(WQCDdir & "CEI_" & NameOfFile & "_" & Date$ & ".xlsm")
' Copy data from Comprehensive Water System Report to detail worksheets
ActiveWorkbook.Worksheets("System Overview").Activate
Sheets("System Overview").Select
ActiveSheet.Unprotect Password:="CDPHE"
Call Populate_General_Info
Call Populate_Administrative_Contact
' Call Populate_Designated_Operator
' Call Populate_Operator
' Call Populate_Population_Info
' ActiveSheet.Protect Password:="CDPHE"
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Else
MsgBox ("Already populated")
End If
' Save the workbook and worksheets
ActiveWorkbook.Save
' turn on messaging
Application.DisplayAlerts = True
On Error GoTo 0
End Sub
Private Sub Populate_General_Info()
Dim PWSID_Combo As String
Dim PWSID As String
Dim PWSName As String
Dim County_Name As String
Dim PWS_Class As String
Dim Activity_Status As String
Dim FoundData As Range
'PWSID is always in A4
PWSID_Combo = Worksheets("Comprehensive Water System Repo").Range("A4")
PWSID = Left(PWSID_Combo, InStr(PWSID_Combo, "-") - 2)
PWSName = Right(PWSID_Combo, Len(PWSID_Combo) - InStr(PWSID_Combo, "-") - 1)
'PWSID
'This assignment gives me an error:
Worksheets("System Overview").Range("B6") = PWSID
'PWS Name
'This assignment gives me an error:
Worksheets("System Overview").Range("D6") = PWSName
'Search for "Principal County Served" and then add 1 row for COUNTY NAME
Set FoundData = Worksheets("Comprehensive Water System Repo").Cells.Find(What:="Principal County Served", _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=False)
County_Name = FoundData.Offset(1, 0)
Worksheets("System Overview").Range("F6") = County_Name
'Search for "Fed Type" and then add 3 rows for PWS Classification
'PWS Classification
Set FoundData = Worksheets("Comprehensive Water System Repo").Cells.Find(What:="Fed Type", _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=False)
PWS_Class = FoundData.Offset(3, 0)
Worksheets("System Overview").Range("B7") = PWS_Class
'Search for "Water System Status" and then add 1 row for Activity Status
Set FoundData = Worksheets("Comprehensive Water System Repo").Cells.Find(What:="Water System Status", _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=False)
Activity_Status = FoundData.Offset(1, 0)
Worksheets("System Overview").Range("D7") = Activity_Status
End Sub
Private Sub Populate_Administrative_Contact()
Dim FoundData As Range
' Search for "Contacts" in column B, save row number
' Search for "Facilities" in colum B, save row number
' search for "AC" (Administrative Contact) between "Contacts" row and "Factilites" row
' Get the line number of AC in column B
' As each field is merged cells, count # of merged cells and offset for next data
' must figure out "Address 2" problem
' Set FoundData = Worksheets("Comprehensive Water System Repo").Cells.Find(What:="Contacts", _
' LookIn:=xlValues, _
' LookAt:=xlPart, _
' MatchCase:=False)
' Contact_Row = FoundData.Row()
'
' Set FoundData = Worksheets("Comprehensive Water System Repo").Cells.Find(What:="Facilities", _
' LookIn:=xlValues, _
' LookAt:=xlPart, _
' MatchCase:=False)
' Facilities_Row = FoundData.Row()
Set FoundData = Worksheets("Comprehensive Water System Repo").Cells.Find(What:="AC", _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=True)
Admin_Row = FoundData.Row
Admin_Column = FoundData.Column
'for each col in FoundData
'if FoundData(col)<>"" then
' copy to corresponding target cell
'end if
'Administrative Contact Name
Worksheets("System Overview").Range("F10") = Admin_Contact_Name
'Administrative Contact Address 1
Worksheets("System Overview").Range("F11") = Admin_Address_1
'Administrative Contact Address 2
Worksheets("System Overview").Range("F12") = Admin_Address_2
'Administrative Contact City
Worksheets("System Overview").Range("F13") = Admin_City
'Administrative Contact State
Worksheets("System Overview").Range("F14") = Admin_State
'Administrative Contact ZIP
Worksheets("System Overview").Range("F15") = Admin_ZIP
'Administrative Contact Phone
Worksheets("System Overview").Range("F16") = Admin_Phone
End Sub
Private Sub Populate_Designated_Operator()
End Sub
Private Sub Populate_Operator()
End Sub
Private Sub Populate_Population_Info()
End Sub