Hi, I am creating a form using Excel. The form will be populated upon creation from outside data, but there will be room for users to enter (but not remove info). I need to have repeating tables. I have created my own version of repeating tables( not using Excel's concept of "table") and I have hyperlinks at the bottom of each table to add or remove rows. The links are linked to a defined name with the range set to the row to be copied or removed. The naming convention is as follows:
lstSection_TableA_B
where A is a number (1 for the first table in a section, 2 for the second table within a section, etc.) and B is also a number (1 for the first subtable within a table, 2 for the second subtable within a table, etc.). The table size is also a defined name with the exact same name as the row defined name except with a different prefix:
numSection_TableA_B
The only way each "table size" defined name is linked to the actual table is through having an identical name (other than the prefix) of the name to be copied.
If that wasn't clear enough let me know. This would obviously be a nightmare to maintain. I was thinking it would be better to create several table objects and maybe have table size and location be organized in a sort of database on a hidden spreadsheet. Does anyone have any suggestions for making this more object-oriented. It is a large form, and I have a large number of defined names.
Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim strLastRowRangeName As String
Dim strTableSizeName As String
strLastRowRangeName = RemoveSheetName(Target.SubAddress)
strTableSizeName = gTABLESIZE_NAME_PREFIX & RemovePrefix(strLastRowRangeName)
'Check if the Last Row Name is in fact a last row'
If (Not HasPrefix(strLastRowRangeName, gLASTROW_NAME_PREFIX)) Then
Call Err.Raise(gTXFB_ERR_RANGE_MISMATCH, "Worksheet_FollowHyperlink", _
gTXFB_ERR_RANGE_MISMATCH_MESSAGE)
'Make sure the last row name exists.'
ElseIf (Not Contains(ActiveSheet.Names, strLastRowRangeName)) Then
Call Err.Raise(gTXFB_ERR_DEFINED_NAME_NOT_FOUND, ActiveSheet.Name _
& ".Worksheet_FollowHyperlink", "Range '" _
& strLastRowRangeName & "': " _
& gTXFB_ERR_DEFINED_NAME_NOT_FOUND_MESSAGE)
'Make sure the table size name exists'
ElseIf (Not Contains(ActiveSheet.Names, strTableSizeName)) Then
Call Err.Raise(gTXFB_ERR_DEFINED_NAME_NOT_FOUND, Application _
.VBE.ActiveVBProject.Name & ".Worksheet_FollowHyperlink", _
"Range '" & strTableSizeName & "': " _
& gTXFB_ERR_DEFINED_NAME_NOT_FOUND_MESSAGE)
Else
'If this is an add link, add a row.'
'Cannot use entire string here in the search because Excel replaces ellipse with special character'
If (InStr(Target.Name, "add")) Then
InsertRow (ActiveSheet.Range(Target.SubAddress))
'If this is a remove link, remove a row'
'Cannot use entire string here in the search because Excel replaces ellipse with special character'
ElseIf (InStr(Target.Name, "remove")) Then
RemoveRow (ActiveSheet.Range(Target.SubAddress))
End If
End If
End Sub