我想将值发布到列A的最后一行,然后将另一个值发布到同一行的列F那上面可能有空的空间。我将如何去完成这个?后列值到A列中的最后一行,另一个值列F列A列中发布的同一行
这是我到目前为止。
Sub test411()
Dim iRow As Integer, iCol As Integer
Dim sEntity As String, sEnt2 As String, sVal1 As Integer
Dim wsEntry As Worksheet
Dim wsUp As Worksheet
Set wsEntry = Worksheets("Entries")
Set wsUp = Worksheets("Sheet1")
Dim lastrow As Long
For iRow = 6 To 7
lastrow = wsUp.Cells(Rows.Count, "A").End(xlUp).Row
wsEntry.Activate
iCount = WorksheetFunction.CountIf(wsEntry.Range(Cells(iRow, 4), Cells(iRow, 11)), ">0")
sEntity = wsEntry.Cells(5, 4).Value
wsUp.Range("A" & lastrow + 1, "A" & lastrow + iCount).Value = sEntity
For iCol = 5 To 11
If Cells(iRow, iCol) > "0" Then
sEnt2 = wsEntry.Cells(5, iCol).Value
sVal1 = wsEntry.Cells(iRow, iCol).Value
lastrow = wsUp.Cells(Rows.Count, "A").End(xlUp).Row
wsUp.Range("A" & lastrow + 1, "A" & lastrow + 2).Value = sEnt2
wsUp.Cells("I", lastrow).Value = sVal1
End If
Next iCol
Next iRow
End Sub
代码是否工作?您需要使用您希望运行的工作表限定'Rows.Count',否则它将在活动工作表上运行。所以我假设你想'lastrow = wsUp.Cells(wsUp.Rows.Count,“A”)。End(xlUp).Row'。 – BruceWayne
我已经使用代码来包含所有的代码。所以不工作的部分是sVal1。 – Angel
你可以做一个while循环吗?你能演示一个例子并添加屏幕截图吗? – Sid29