缩短我的代码

时间:2014-10-02 13:59:42

标签: excel excel-vba excel-2003 vba

我正在努力推出一份有关问题的工作问卷。用户可以使用“是”,“是”,“可能”和“否”等单选按钮进行回复。该调查问卷包含在名为manager的表格中。

如果他们选择是或否,我想将问题复制到标有是和否的表格中的单独表格,无论他们选择是或否。此表称为“跟进”。

我有200多个问题,所以你可以理解我为什么要缩短代码。

我的第二个问题是如果他们改变主意从否改为是,我想从no列中删除复制的问题。当它们改变主意时,问题就会被复制到两者中。

以下是我已经拥有的代码:

Private Sub OptionButton1_Click()

If OptionButton1.Value = True Then 'This is yes
    Worksheets("Manager").Range("B3").Copy _ 'Within B3 is the person's name
    Destination:=Worksheets("Follow Up").Range("B3") 'In this B3 I need the person's name
End If

If OptionButton1.Value = True Then
    Worksheets("Manager").Range("B9").Copy _ 'B9 holds the question
    Destination:=Worksheets("Follow Up").Range("B6") 'B6 is where I want it to go
End If
End Sub


Private Sub OptionButton4_Click()

If OptionButton4.Value = True Then 'This is for no
    Worksheets("Manager").Range("B3").Copy _
    Destination:=Worksheets("Follow Up").Range("B3")
End If

If OptionButton4.Value = True Then
    Worksheets("Manager").Range("B9").Copy _
    Destination:=Worksheets("Follow Up").Range("C6")
End If

End Sub

1 个答案:

答案 0 :(得分:0)

这是一种方法,但如果不了解其他问题的结构,很难提供真正有用的答案。

下面的代码仍然依赖于对给定问题的范围(B3,B6,C6等)进行硬编码:但是如果您的问题都是相同的结构,那么应该可以再添加一个参数{{ 1}}所以它知道应该操作哪些单元格。

TheAnswer
相关问题