![](/img/trans.png)
[英]EXCEL VBA - Loop through cells in a row, if not empty, copy cell value into another row until next row not empty
[英]Excel VBA - generate next empty row number and copy to spreadsheet
VBA问题。
我是VBA的新手,我想看看是否可以让我的代码为我做更多的事情。 当前,该代码在我的共享驱动器上打开一个电子表格,检查下一个空行,并向我提供行号。 例如,我有39行数据,而第40行为空,它的编号为40。
目前,它在msgbox中为我提供了此号码。 我想要做的是将该数字输入到打开的工作表中的单元格中。
该号码实际上是一个ID,也可以向我们显示已提交了多少“投诉”。
有任何想法吗?
这是我目前的代码:
Sub LastRowWithData()
Dim lastRow As Long
Dim ConcernMemosMaster As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set ConcernMemosMaster = Workbooks.Open("N:\myfilepath")
lastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row + 1
ConcernMemosMaster.Close
Application.DisplayAlerts = True
MsgBox lastRow
End Sub
以下代码将在活动工作表单元格A1
lastRow
行数+ 1( 您的lastRow
变量 )。
如果要在其他单元格中而不是修改行
currentSheet.Range("A1") = lastRow
并用其他单元格引用替换A1
。
您的宏:
Sub LastRowWithData()
Dim currentSheet As Worksheet
Set currentSheet = ActiveSheet
Dim lastRow As Long
Dim ConcernMemosMaster As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set ConcernMemosMaster = Workbooks.Open("N:\myfilepath")
lastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row + 1
ConcernMemosMaster.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
currentSheet.Range("A1") = lastRow
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.