根据单元格信息填充Dropbox,然后根据选定的信息填充其他单元格

时间:2018-02-20 16:05:18

标签: excel-vba validation dropbox offset vba

我有633行具有身份证号码和规格的车辆名称。在车辆1的行中,我想使用下拉列表选择机箱类型并使用此数据填充一些行。在机箱工作表中,我有一个机箱列表,其中包含可以使用的车辆编号。例如。底盘4567可以用在车辆1,37,18上。车辆1可以使用底盘4567,4657和8865。还有变速箱等。然后,主车辆规格表有多个下降,如果选择将改变该行中车辆的规格。 我该怎么做呢。 688车? 任何帮助都会做,因为我一直试图寻找例子。我想用vba做excel。

主要表格:The main sheet where the dropboxes will be

悬挂表:The suspension sheet that will populate the suspension drop box based on the vehicles id in the row and when changed will populate the cells with data on that suspension.

一般车辆详情The general vehicle details and vehicle id used to populate all fields in the main sheet

这些工作表都连接到Web Api并每周更新。这一部分全部有效。只是投递箱......

尝试了以下几段代码:(更新代码)

Private Sub Sheet_Initialize()

Dim sn, e
Dim rngTurTank As Range
Dim oDictionary As Object
Dim x As Integer

Set oDictionary = CreateObject("Scripting.Dictionary")
Set rngTurTank = Sheets("Turrets").Range("b2" &   Rows.Count).End(xlUp).Offset(1)

    With Sheets("Total details").cbTurret
        For Each cel In rngTurTank
            If Doictionary.exists(cel.Value) Then
            'Do Nothing
            Else
                oDictionary.Add cel.Value, 0
                .AddItem cel.Value
            End If
        Next cel
    End With

    Dim iTurTank As Long

        lbTurTank.Clear
        On Error Resume Next
        iTurTank = Sheets("Turrets").Range("B2" & Rows.Count).End(xlUp).Offset(1).Count
        Set rngTurTank = Sheets("Turrets").Range("B2" & Rows.Count).End(xlUp).Offset(1).Value
        If iTurTank > 0 And rngTurTank = Range("A3").Value Then
            lbTurTank.RowSource = Sheets("Turrets").Range("D2:D")
        Else
            lbTurTank.RowSource = ""
            lbTurTank.AddItem "Empty"
        End If

这些没有用,所以我尝试了这个:

'the reference string to the source range
Dim strTurretRange As String

'Turrets
strTurretRange = Sheets("Turrets").Range("D2",    Range("D2").End(xlDown)).Select
    With Sheet5.Range("M3").Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
        Operator:=xlBetween, Formula1:=strTurretRange
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub

如果tank id相同,我该如何填充列表。即。 colomn A

尝试2号

With Sheet5.Range("M3").Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
        Operator:=xlBetween, Formula1:="=VLOOKUP(A3;allTurrets;3;0)"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

我尝试了3号:

With Sheet5.Range("M3").Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
        Operator:=xlBetween, Formula1:="=INDEX(sTurrets;MATCH(A3;sTank_id_turret;0))"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

这最后一个有效,但只给我一个返回值,我需要在下拉框中选择4到5个值?

尝试编号4:

使用以下内容:= OFFSET(sTurrets; MATCH($ A $ 3; sTank_id_turret; 0); 0; COUNTIF(sTank_id_turret; $ A $ 3); 1) 获取正确数量的匹配,但不是第一个正确匹配。即如果tank_id 14913的炮塔名称是' t34 mod,Cruizer Mk1,Cz03 LTvz35,Leophard Prototype A1和Leophard Prototype A2。该公式省略了t34 mod,然后在保时捷T169中添加,用于tank_14914。

  1. 按顺序加载完整列表我错过了什么?
  2. 默认情况下有没有办法加载列表中的最后一个值?
  3. 如何填充DV右侧的单元格? 任何有关这方面的帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我对此有了更多的了解,我从数据中创建了一个表格。我有以下代码:

Application.Goto Reference:="sTank_id_turret"

With Sheet5.Range("M3").Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
        Operator:=xlBetween, Formula1:="=VLOOKUP(A3;tblTurrets;3;0)"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

我这样做,因为我在这张纸上有5种不同的验证,从5行不同的所有1行。共有650行信息。

它只是在下拉列表中给出了1个值。我必须有4到5个可供选择。为什么 为什么我只有1