Sub acqmodel()
Dim f_rowcnt As Long, lstrow As Long, floop As Long, fndrow As Long, i As Long
Dim response
Dim mcval As Long
Dim c1 As String, c2 As String
Dim ifmTxtModel As String
Dim drow As Long, trow As Long
Dim grp As String, lengrp As Long, noCommaLength As Long, commacnt As Long, nopart As Long
Dim cntPL As Long, nnames As Long
Dim host As String, partialName As String, mfname As String
Dim result As Boolean, exists As Boolean
Dim FolderPath As String, inimodel As String
Dim nrngUXDump As Range, foundCell As Range
Dim ttle As String, tmdl As String, retrow As Long, tcr As Long
Dim myrow As Long
f_rowcnt = 0
With ws_ifm
If .AutoFilterMode Then .AutoFilterMode = False
lstrow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Range("A2").AutoFilter Field:=1, Criteria1:=txt_model
f_rowcnt = [subtotal(103,A:A)] - 2
Debug.Print f_rowcnt
If f_rowcnt = 0 Then
response = MsgBox(txt_model & " does not exist in the catalogue." & Chr(13) & "Proceed to model entry?", vbYesNo, "Error")
If response = vbYes Then
lstrow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
reset_dump
open_folder txt_model
'open webspage
If Right(txt_model, 1) = "." Then
ifmTxtModel = Left(txt_model, Len(txt_model) - 1)
Else
ifmTxtModel = txt_model
End If
SearchWebPage ifmTxtModel
Else
mbevents = False
frm_reset
mbevents = True
End If
Exit Sub
Else
reset_dump
.UsedRange.SpecialCells(xlCellTypeVisible).Copy _
Destination:=ws_dump.Range("A2")
ws_dump.Rows("2:3").EntireRow.Delete
f_rowcnt = WorksheetFunction.CountA(ws_dump.Columns(1))
'acquire database row number
For floop = 2 To f_rowcnt '- 1
c1 = ws_dump.Range("A" & floop)
c2 = ws_dump.Range("C" & floop)
fndrow = -1
For i = 3 To lstrow
If ws_ifm.Cells(i, 1).Value = c1 And ws_ifm.Cells(i, 3).Value = c2 Then
fndrow = i
ws_dump.Range("K" & floop) = i
Exit For
End If
Next i
Next floop
'open model folder
open_folder txt_model
'open webspage
If Right(txt_model, 1) = "." Then
ifmTxtModel = Left(txt_model, Len(txt_model) - 1)
Else
ifmTxtModel = txt_model
End If
SearchWebPage ifmTxtModel
End If
End With
'prepare listbox data range
With ws_dump
.Activate
lstrow = ws_dump.Cells(ws_dump.Rows.count, "A").End(xlUp).Row
.Range("C2:C" & lstrow).Copy Destination:=.Range("U2")
'assess model collected, "" if title not model checked
For i = 2 To lstrow
mcval = .Range("J" & i)
If IsNumeric(mcval) Then
.Range("W" & i) = "YES"
Else
.Range("W" & i) = "NO"
End If
Next i
.Range("U" & lstrow + 1) = "ADD Title"
'determine host (primary or secondary)
For i = 2 To lstrow
.Range("Z2:AB15").Clear
.Range("AA2") = txt_model
'check if primary
If .Range("B" & i) = "" Then 'no participants so only primary
.Range("X" & i) = "" 'leave empty. Populate with alternate when alternate host's title (alphabetical)
'underline the model name (in database) as host if not already underlined
If .Range("A" & i).Font.Underline = xlUnderlineStyleNone Then
drow = .Range("K" & i)
ws_ifm.Range("A" & drow).Font.Underline = xlUnderlineStyleSingle
End If
.Range("Z2") = "HOST"
Else 'inspect participants
'gather names based on comma count
grp = .Range("B" & i)
lengrp = Len(grp)
noCommaLength = Len(Replace(grp, ",", ""))
commacnt = lengrp - noCommaLength
If commacnt = 0 Then 'only one name
nopart = 2
.Range("AA3") = grp
'.Range("AA2:AA3").Sort key1:=.Range("AA2"), order1:=xlAscending, Header:=xlNo
grp = .Range("AA2") & ", " & .Range("AA3")
Else
nopart = commacnt + 1
ExtractNamesToColumn grp
End If
'integrity check
cntPL = Application.WorksheetFunction.CountA(ws_dump.Columns("AA"))
'If cntPL <> nopart Then Stop '(count of participant names in dump not equal to names in database cell)
'get the first name in the list alphabetically
host = FirstNameAlphabetically(grp)
host = RTrim(host)
MsgBox "The host should be: " & host
Set foundCell = ws_dump.Columns("AA").Find(host, LookIn:=xlValues)
'MsgBox "Host " & host & " in cell " & foundCell.Address
foundCell.Offset(0, -1).Value = "HOST"
'determine in primary comes before alternate to determine host
result = IsAlphabeticallyBefore(txt_model, host)
If result = False Then
.Range("X" & i) = host 'if the altname (underlined) comes before primary, than altname hosts, else primary hosts (underlined)
End If
'### check and underline altname in database participants cell of
End If
'populate title based on whether in the folder of not (folder should already be open to txt_model
'partialName
partialName = .Range("C" & i)
'folder path
If .Range("X" & i) = "" Then 'txt_model is the host
mfname = Trim(txt_model)
If Right(mfname, 1) = "." Then mfname = Left(mfname, Len(mfname) - 1)
Else 'alternate is the host
mfname = Trim(host)
If Right(mfname, 1) = "." Then mfname = Left(mfname, Len(mfname) - 1)
'check altnames directory for title (partial)
End If
inimodel = Left(mfname, 1)
FolderPath = "O:\IFM\" & inimodel & "\" & mfname
exists = FileExistsWithPartialName(FolderPath, partialName)
If exists Then
.Range("V" & i) = "OK"
trow = .Range("K" & i)
'update txt_model entry
ws_ifm.Rows(trow).EntireRow.Font.Color = RGB(84, 130, 53)
ws_ifm.Range("I" & trow).Value = "OK"
'update participants
tcr = 3
Do While .Cells(tcr, 27) <> ""
ttle = .Range("C" & i)
tmdl = .Range("AA" & tcr)
MsgBox "ttle: " & ttle & Chr(13) & "tmdl: " & tmdl
myrow = fndrow(ttle, tmdl)
MsgBox tmdl & " found at row: " & myrow, , ttle
Loop
'acknowledge participants collection
'create participant list (dump A
End If
Next i
'create named range of dump (U:X)
'nrngUXDump.Delete
.Range("U2:X" & lstrow + 1).Name = "nrngUXDump"
'check value of txt_model to ensure periods exist
With IFM_Title
.tbx_titlecnt.Value = WorksheetFunction.CountIf(ws_dump.Columns(1), txt_model)
.tbx_checkedcnt.Value = WorksheetFunction.CountIf(ws_dump.Columns("W"), "YES")
.tbx_collectedcnt.Value = WorksheetFunction.CountIf(ws_dump.Columns("V"), "OK")
With .lbx_collections
.columnCount = 4 'collected, title, primary, model checked
.ColumnWidths = "140, 30,30,68"
.List = Application.Range("nrngUXDump").Value
End With
End With
End With
End Sub