0

编辑:几乎解决了参考我最近的评论和相关代码。

我希望用户表单根据用户表单上的选择填写工作表的 A 列

用户表单有 16 个复选框,两个包含月份(jan-dec)的列表框和一个包含年份(两位数)的列表框

我希望用户表单填写字符串中的 XX YYY 和 ZZ 并为每个复选框选择生成两个值(每个选择的月份一个)并将这些值一个接一个地粘贴到 A 列中

(G:\Reporting\XX_MISSE_YYY20ZZ.xls)

其中 XX 对应于我选择的复选框(总共可以在 1-16 个选项之间), YYY 对应于月份的列表框选择(重申一下,我希望从列表框中的两个月选择中生成两个值)和 ZZ 对应年份的两位数列表框选择

换句话说...

我希望用户框做的是,如果我在我的用户表单上选择与 AH 和 AD 对应的复选框(例如),并且我为月份列表框选择 mar 和 Apr,为年份列表框选择 13,我在 A 列中的结果将是

生成的第一个值将是 A1 列中的 (G:\Reporting\AH_MISSE_MAR2013.xls)

生成的第二个值将是 A2 列中的 (G:\Reporting\AH_MISSE_APR2013.xls)

生成的第三个值将是 A3 列中的 (G:\Reporting\AD_MISSE_MAR2013.xls)

生成的第四个值将是 A4 列中的 (G:\Reporting\AD_MISSE_APR2013.xls)

4

1 回答 1

1
Private Sub cbtnSubmit_Click()
Dim sMonth1 As String
Dim sMonth2 As String
Dim sYear As String
Dim cMyControl As Control
Dim TargetCell As Range
Dim iOff As Integer

    sMonth1 = Me.lbMonth1.Value 'get the first month from the listbox
    sMotnth2 = Me.lbMonth2.Value 'get the second month from the listbox
    sYear = Me.lbYear.Value 'get the year

    TargetCell = ThisWorkbook.Worksheets(1).Range("A1") 'Where we want to start outputing
    iOff = 0 'Start output with no cell offset

    For Each cMyControl In Me.Controls 'Loop through all control on the form
        If TypeName(cMyControl) = "CheckBox" Then 'Finding the Checkboxes
            'then writing the values to the excel sheet
            TargetCell.Offset(iOff, 0).Value = "G:\Reporting\" + cMyControl.Tag + "_MISSE_" + sMonth1 + ".xls"
            TargetCell.Offset(iOff, 1).Value = "G:\Reporting\" + cMyControl.Tag + "_MISSE_" + sMonth2 + ".xls"
            'after I've written two value, "move" down two cells
            iOff = iOff + 2
        End If
    Next
End Sub
于 2013-05-07T21:47:37.903 回答