将值发布到A列中的最后一行,将另一个值发布到列A中发布的同一行

时间:2017-04-18 15:06:46

标签: excel vba excel-vba

我试图将一个值发布到A列的最后一行,然后将另一个值发布到同一行中的F列,但是在该行之上可能有空的空格。我将如何实现这一目标?

这是我到目前为止所拥有的。

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

1 个答案:

答案 0 :(得分:1)

也许以下解决方案可以提供帮助:

{'AddFilterViewRequest' : {
      'AddFilterViewResponse': {
      'Filter' : {
                  'FilterView': {
                  'title' : "Hide rows with errors",
                  'range': {'sheetId': sheet_id,
                            'startRowIndex': 0,
                            'endRowIndex': 2,
                            'startColumnIndex': 1,
                            'endColumnIndex': 31}
                  }
      }
      }
}}

说明:我没有将单元格的值赋给变量,而是使用此变量来设置另一个单元格,而是采用短路径并立即将最终单元格设置为原始单元格的值(中间没有变量) 。像这样,您不必担心Excel VBA变量和数据类型。