为什么大多数时间我运行UserForm时都在Excel 2013中出现运行时错误-2147417848(80010108)?

问题描述 投票:4回答:2

任务:

我在Excel2013中工作。我试图用VBA编写一个用户窗体,以将参数添加到动态命名范围中。所有命名范围都保存在一张纸中,并使用insert> table创建。我选择范围,显示现有值并获取新值。一切顺利,直到我真正要为范围增加价值。

问题:

当我尝试运行UserForm时,Excel通常会关闭。说:
“运行时错误'-2147417848(80010108)'对象'范围'的方法X失败”

在分解代码的不同阶段,使用了不同的方法(上次使用'_Default'进行检查)。

症状:

  1. 在我发现这一行之后,我得到了错误:

    Cells(y, x) = v
    其中yx是整数,而v是我从用户表单中获得的字符串。在调试期间,我检查了所有值是否已定义并具有值。而且,

    立即窗口

    可以手动输入相同的数字(而不作为变量)!
  2. 大多数情况下它是行不通的,尽管它确实完成了工作。
  3. 如果有人能说出它破裂的原因,将不胜感激!

某些标题和可能的值在Unicode中是重要的,尽管我也尝试将其全部用英语表达。

Private Sub UserForm_Initialize() ' Preparing all controls of UserForm Sheet2.Activate Me.LB_parameter.SetFocus Me.LB_parameter.value = "" Me.LB_elements.RowSource = "" Me.L_element.Enabled = False Me.TB_element.Enabled = False Me.TB_element.Locked = True Me.Btn_Add.Enabled = False Me.Btn_Add.Locked = True End Sub Private Sub LB_parameter_DblClick(ByVal Cancel As MSForms.ReturnBoolean) ' Filling the existing list of values for the selected parametr If Me.LB_parameter.value <> "" Then Me.LB_elements.RowSource = "D_" & Me.LB_parameter.value & "s" Me.L_element.Enabled = True Me.TB_element.Enabled = True Me.TB_element.Locked = False Me.TB_element.SetFocus End If End Sub Private Sub TB_element_DblClick(ByVal Cancel As MSForms.ReturnBoolean) ' Catching the event of filling out the potential new value Me.Btn_Add.Enabled = True Me.Btn_Add.Locked = False Me.L_element.Enabled = False Me.TB_element.Enabled = False Me.TB_element.Locked = True End Sub Private Sub Btn_Add_Click() If Me.TB_element.Text = "" Then ' Check if Empty MsgBox ("Âû íå âïèñàëè çíà÷åíèå!") ' Reset the UserForm Me.Btn_Add.Enabled = False Me.Btn_Add.Locked = True Me.L_element.Enabled = True Me.TB_element.Enabled = True Me.TB_element.Locked = False Me.TB_element.SetFocus Else ' check if exists Dim str For Each str In range("D_" & Me.LB_parameter.value & "s") If Me.TB_element.Text = str Then MsgBox ("Ââåäåííîå çíà÷åíèå óæå ñóùåñòâóåò!") ' reset the UserForm Me.Btn_Add.Enabled = False Me.Btn_Add.Locked = True Me.L_element.Enabled = True Me.TB_element.Enabled = True Me.TB_element.Locked = False Me.TB_element.SetFocus Me.TB_element.value = "" Exit Sub End If Next str ' add to the range here Dim x As Integer, y As Integer, v As String y = range("D_" & Me.LB_parameter.value & "s").Rows.Count + 2 x = Me.LB_parameter.ListIndex + 1 v = Me.TB_element.value ' Next line causes break down Cells(y, x) = v MsgBox ("Âû äîáàâèëè ýëåìåíò:'" & v & "' äëÿ ïàðàìåòðà '" & Me.LB_parameter.value & "'.") ' Reset the Userform Me.LB_parameter.SetFocus Me.LB_parameter.value = "" Me.LB_elements.RowSource = "" Me.L_element.Enabled = False Me.TB_element.Enabled = False Me.TB_element.Locked = True Me.Btn_Add.Enabled = False Me.Btn_Add.Locked = True End If End Sub

Sheet我将值添加到参数和namedranges窗口:

Sheet I add values to the parametrs and namedranges window

用户窗体布局:

The UserForm layout

[任务:我在Excel2013中工作。我试图用VBA编写一个用户窗体,以将参数添加到动态命名范围中。所有命名范围都保存在一张纸中,并使用insert> table创建。我选择...

excel vba excel-vba runtime-error excel-2013
2个回答
1
投票
Cells(y, x) = v

1
投票
© www.soinside.com 2019 - 2024. All rights reserved.