使用Excel VBA激活对选择值的组合框操作

时间:2015-09-09 06:02:45

标签: excel vba excel-vba combobox

我正在显示一个组合框,其中包含工作簿的所有工作表名称。 如果我选择一个值,我希望Excel跳转到所选的工作表。

我尝试在此代码上执行激活代码行,但它似乎不起作用。

//scroll down as soon as launches the app and wait for 5 to 10 seconds then scroll to top u will see top 5 cells are updates with progress 5
- (void)PostNotification
{
   packeData *data = [[packeData alloc]init];
   data.key = arc4random()%5; //only top 5 cells are modify other wont modify
   data.process = [NSString stringWithFormat:@"%ld",5];//updates with some same progress lates give it as 5 //( data.key  + arc4random() % 100)];
  [[NSNotificationCenter defaultCenter] postNotificationName:@"theSender" object:data];
}

1 个答案:

答案 0 :(得分:2)

您要在Change Event中添加工作表名称吗?这将重新启动变更事件。我会建议填充,例如UserForm_Initialize事件。

这是你在尝试的吗?

Dim Sh As Worksheet

Private Sub UserForm_Initialize()
    For Each Sh In ThisWorkbook.Sheets
        If Sh.Name <> "Inputs" Then
            ComboBox1.AddItem Sh.Name
        End If
    Next

    ComboBox1.Style = fmStyleDropDownList
End Sub

Private Sub ComboBox1_Change()
    With ThisWorkbook.Sheets(ComboBox1.Text)
        .Visible = xlSheetVisible
        .Activate
    End With
End Sub

我的假设

您在Userform上拥有此Combobox。如果没有,则对代码进行相关更改。但要点仍然是一样的。

跟进评论

在工作表上添加一个按钮。将其命名为Refresh并使用此代码

Dim Sh As Worksheet

Private Sub CommandButton1_Click()
    ComboBox1.Clear

    For Each Sh In ThisWorkbook.Sheets
        If Sh.Name <> "Inputs" Then
            ComboBox1.AddItem Sh.Name
        End If
    Next

    ComboBox1.Style = fmStyleDropDownList
End Sub

Private Sub ComboBox1_Change()
    With ThisWorkbook.Sheets(ComboBox1.Text)
        .Visible = xlSheetVisible
        .Activate
    End With
End Sub