Excel VBA 用户窗体组合框不显示命名范围列表

问题描述 投票:0回答:1

我正在尝试使用命名范围“rngEnclosure”填充组合框,但它没有填充组合框,但没有错误消息。奇怪的是,我有另一个 ComboBox 填充了相同的列表并且它可以工作。

损坏的组合框

工作组合框

此行不会填充组合框:

'Fill primary enclosure material combo box
    cbPrimeEnclosureMat.List = Application.WorksheetFunction.Transpose(Range("rngEnclosure"))

但是这一行确实:

'Fill secondary enclosure material combo box
    cbSecEnclosureMat.List = Application.WorksheetFunction.Transpose(Range("rngEnclosure"))

用户窗体初始化事件的完整代码:

Private Sub UserForm_Initialize()
'POPULATE FIELDS UPON USERFORM INITIALIZATION
'PROJECT INFORMATION
'Empty project name text box
    txbProjectName.Value = ""

'Empty project type combo box
    cbProjectType.Clear

'Fill project type combo box
    cbProjectType.List = Application.WorksheetFunction.Transpose(Range("rngProjectType"))

'Empty reporting combo box
    cbReported.Clear

'Fill reporting combo box
    cbReported.List = Array("Yes", "No")

'Empty GSF text box
    txbGSF.Value = ""
    
'Empty number of floors text box
    txbFloors.Value = ""
    
'Empty F2F text box
    txbF2F.Value = ""

'Empty footprint shape combo box
    cbFootprint.Clear

'Fill footprint shape combo box
    cbFootprint.List = Application.WorksheetFunction.Transpose(Range("rngFootprint"))

'Empty articulation combo box
    cbArticulation.Clear

'Fill articulation combo box
    cbArticulation.List = Application.WorksheetFunction.Transpose(Range("rngArticulation"))
    
'FOUNDATION AND PODIUM
'Empty foundation type combo box
    cbFoundation.Clear

'Fill project type combo box
    cbFoundation.List = Application.WorksheetFunction.Transpose(Range("rngFoundation"))

'Empty SOG thickness text box
    txbSOGThickness.Value = ""

'Empty number of piles text box
    txbPiles.Value = ""
    
'Empty pile depth text box
    txbPileDepth.Value = ""

'Empty foundation type combo box
    cbPodium.Clear

'Fill project type combo box
    cbPodium.List = Array("Yes", "No")

'Empty number of podium floors text box
    txbPodiumFloors.Value = ""

'STRUCTURE
'Empty floor slab thickness text box
    txbFloorSlabThickness.Value = ""

'Empty floor slab material combo box
    cbFloorSlabMat.Clear

'Fill floor slab material combo box
    cbFloorSlabMat.List = Application.WorksheetFunction.Transpose(Range("rngFloorSlab"))

'Empty primary structure % text box
    txbPrimeStructurePerc.Value = ""

'Empty primary structure material combo box
    cbPrimeStructureMat.Clear

'Fill primary structure material combo box
    cbPrimeStructureMat.List = Application.WorksheetFunction.Transpose(Range("rngStructure"))

'Empty secondary structure % text box
    txbSecStructurePerc.Value = ""

'Empty secondary structure material combo box
    cbSecStructureMat.Clear

'Fill secondary structure material combo box
    cbSecStructureMat.List = Application.WorksheetFunction.Transpose(Range("rngStructure"))

'ENCLOSURE
'Empty primary enclosure % text box
    txbPrimeEnclosurePerc.Value = ""

'Empty primary enclosure material combo box
    cbPrimeEnclosureMat.Clear

'Fill primary enclosure material combo box
    cbPrimeEnclosureMat.List = Application.WorksheetFunction.Transpose(Range("rngEnclosure"))

'Empty secondary enclosure % text box
    txbSecEnclosurePerc.Value = ""

'Empty secondary enclosure material combo box
    cbSecEnclosureMat.Clear

'Fill secondary enclosure material combo box
    cbSecEnclosureMat.List = Application.WorksheetFunction.Transpose(Range("rngEnclosure"))

'GLAZING
'Empty W2W text box
    txbW2W.Value = ""

'Empty primary glazing % text box
    txbPrimeGlazingPerc.Value = ""

'Empty primary glazing material combo box
    cbPrimeEnclosureMat.Clear

'Fill primary glazing material combo box
    cbPrimeGlazingMat.List = Application.WorksheetFunction.Transpose(Range("rngGlazing"))

'Empty secondary glazing % text box
    txbSecGlazingPerc.Value = ""

'Empty secondary glazing material combo box
    cbSecGlazingMat.Clear

'Fill secondary glazing material combo box
    cbSecGlazingMat.List = Application.WorksheetFunction.Transpose(Range("rngGlazing"))

'Set focus on project name text box
    txbProjectName.SetFocus
End Sub
excel vba combobox userform
1个回答
0
投票

这是一个可变错误。在代码中进一步输入错误的变量,导致组合框在填充列表后被清除。

'Empty primary glazing material combo box
cbPrimeEnclosureMat.Clear

应该是:

'空的初级玻璃材料组合框 cbPrimeGlazingMat.Clear

© www.soinside.com 2019 - 2024. All rights reserved.