来自另一个工作表的VBA数据验证

时间:2014-10-17 13:44:28

标签: vba charts

我目前有2个工作表。 Sheet1和Sheet3。在Sheet3中,我有多个公开交易的公司在第一行。在每个公司下,我都有一个图表/图表名称,我可以通过另一个与公司相关的工作簿找到。

在sheet1中,我有一列公司和一列图表。我想创建一个下拉列表,允许用户选择图形并以PDF或扩展版本打开它。我该怎么做呢?

Sub appendGraphs()
Dim source, target As Worksheet
Dim LC, RC As Integer
Set source = Sheet5
Set target = Sheet1
LC = source.Cells(1, Columns.Count).End(xlToLeft).Column

For i = 2 To LC ' collect strings from each column and store it to tempList to feed to datavalidation

    RC = source.Cells(Rows.Count, i).End(xlUp).Row
    ReDim tempList(1 To RC) As String
    For n = 2 To UBound(tempList)
        tempList(n) = source.Cells(i, n).Value
    With target.Cells(findRowB(source.Cells(1, i).Value, Sheet1), 10).Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
        Operator:=xlBetween, Formula1:=tempList
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True

    End With

    Next

Next

End Sub

Function findRowB(x As String, Optional y As Worksheet) As Integer 'finds specific row to start writing values in
Dim expectedRow As Range
Dim wbsheet As Worksheet
If y Is Nothing Then
    Set wbsheet = ActiveSheet
Else
    Set wbsheet = y
End If
Set expectedRow = wbsheet.Range("C:C").Find(What:=x, LookIn:=xlValues, Lookat:=xlWhole)
findRowB = expectedRow.Row

结束功能

1 个答案:

答案 0 :(得分:0)

没有人会为你做那些vba。只需谷歌各个部分,在这里我将帮助你开始。

创建一个下拉列表, https://support.office.com/en-us/article/create-a-dropdown-list-7693307a-59ef-400a-b769-c5402dce407b

链接它, http://software-solutions-online.com/2014/02/21/excel-vba-drop-down-lists/

将其另存为pdf, http://www.contextures.com/excelvbapdf.html

Google是你的朋友!

或使用记录宏。

随意提问。