我正在尝试使用excel VBA中的依赖组合框,但我收到以下错误:我无法理解为什么会得到。帮助会很棒。
Run-time error '1004': The selection is not valid, There are several possible reasons:
.alignright {
width: 103px;
height: 192px;
}
答案 0 :(得分:1)
您的最终With
不正确。尝试:
With Worksheets("Sheet5")
For colsCounter = 1 To lastColumn
With .Columns(colsCounter)
lastRow = Sheet5.Cells(Sheet5.Rows.Count, colsCounter).End(xlUp).Row
With .Range(.Cells(1, colsCounter), .Cells(lastRow, colsCounter))
.CreateNames Top:=True
End With
End With
Next
End With
如果它是前一个块的子项,则只能嵌套With
块:
'// This will work fine
With Sheets("Sheet1")
With .Range("A1") '// Notice the '.' before Range()
.Value = "test"
End With
End With
'// This will not
With Sheets("Sheet1")
.Range("A1").Value = "test"
With Sheets("Sheet2")
.Range("A1").Value = "test"
End With
End With
在第二个示例中,您必须在开始下一个With
块之前关闭它。