我正在使用Google表单为儿童夏令营创建一个注册表单。每个孩子的价格取决于多种因素,例如是否有兄弟姐妹,如果孩子在特定团队中比赛,如果他有四个手臂等等。
我想根据这些因素显示价格(每个因素都在表格中提到)。使用外部函数有更优雅的方法吗?它可能是一个Google脚本,它接收到目前为止给出的答案并返回代表此价格的collapse/extend
。快速和肮脏的解决方案是使用多个页面并根据答案重定向用户,但它不是很好也不整洁。
答案 0 :(得分:1)
您可以使用1个Google表单执行此操作,以便每个人都使用。以下只是我如何做到这一点的一个例子。
表格
和代码
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
' Skip any changes unless it's cell 'Movies'!$C$4
If Target.Address(0, 0) <> "C4" Then Exit Sub
' Columns from Theater 1 to the gap, change for expansion
Const TheatersColumns As String = "AD:AN"
Dim ws As Worksheet, MaxTheathers As Integer
Dim entireRange As Range, hideRange As Range, GapColumn As Range
Application.ScreenUpdating = False
For Each ws In ThisWorkbook.Worksheets
' Make changes if it's not the caller worksheet
If ws.Name <> Target.Worksheet.Name Then
Set entireRange = ws.Columns(TheatersColumns) ' Columns from Theater 1 to the gap (#theaters+1)
MaxTheathers = entireRange.Count - 1 ' Last col is blank (GapColumn)
Set GapColumn = entireRange.Columns(MaxTheathers + 1)
entireRange.EntireColumn.Hidden = False
Set hideRange = ws.Range(GapColumn.Offset(, -(MaxTheathers - CLng(Target.Value))), GapColumn.Offset(, -1))
' Hide only when hideRange doesn't unclude GapColumn
If Intersect(hideRange, GapColumn) Is Nothing Then
hideRange.EntireColumn.Hidden = True
End If
Set hideRange = Nothing
Set entireRange = Nothing
Set GapColumn = Nothing
End If
Next ws
Application.ScreenUpdating = True
End Sub
点击提交后,价格就会显示出来。