如何在VBA中将变量设置为行号?

我有一个代码,该代码在节的末尾插入一行,然后从上方复制公式。

我唯一的问题是我不确定如何将诸如“ iRow”之类的变量定义为动态范围。

下面的代码是仅复制上方行中公式的部分。如果我将iRow设置为固定数字,则整个代码都有效。但是,我需要“ iRow”变量来接受可以在B列中找到值“ 2”的任何行号。

我尝试了诸如Columns(“ B:B”)。Find(What:= 2)之类的事情。

@DragSource("key",{
  beginDrag(props,monitor,component) {
    // component.node === undefined ¯\_(ツ)_/¯
  }
},...)
class MySourceComponent extends Component {
  render() {
    return this.props.connectDragSource(
      <div ref={node => this.node = node}>The size of this node should be measured and passed into drag target</div>
    )
  }
}
ydgdyan 回答:如何在VBA中将变量设置为行号?

回答您的问题:

  

”但是,我需要“ iRow”变量来接受行中的任何行号   可以在B列中找到值“ 2”。

您可能需要类似的东西:

Sub test()

Dim iRow as Long
With Sheet1 'Use an explicit sheet reference,use a sheets CodeName
    iRow = .Columns(2).Find(2,lookat:=xlWhole).Row
    'Rest of code
End With

End Sub

这将获得第一次出现的2的行号。但是,如果未找到2的值,则会产生错误。

,

如果要动态行计数器,则需要计数。使用以下代码,例如,如果将列设置为B并使用计数器,它将始终查找最后一行。

例如

Application.ScreenUpdating = True
Dim iRow As Integer
'This will give the last number in the row that is filled
iRow = .Range("B" & .Rows.Count).End(xlUp).Row
'Select row
Rows(iRow - 1).EntireRow.Copy
'Paste it into the new row
Rows(iRow).PasteSpecial

 Rows(iRow).SpecialCells(xlConstants).ClearContents

Application.CutCopyMode = False

我也会声明工作簿和工作表,但是在此示例中,我将其省略了。

本文链接:https://www.f2er.com/3170104.html

大家都在问