Copy ranges to master table and remove ranges from master table if cell = 0

前端 未结 2 1617
旧时难觅i
旧时难觅i 2021-01-23 16:38

There are 10 Sheets (Sheet1...Sheet10) with tables in the same range (C25:G34 & C42:N51).

The rows have to be copied if the \'Total Weight\' column has valu

相关标签:
2条回答
  • 2021-01-23 16:47

    You're getting the error because you have the row and column values swapped around. The row parameter comes first and then comes the column parameter.

    Your code should read as follows:

    If Cells(cRow, cCol).Value = "0" Then
        Range(Cells(rRow, rCol), Cells(cRow, cCol)).ClearContents
    End If
    

    You are trying to clear column 11 from rows 3 to 14 of the "To DNP" worksheet, which obviously contains merged cells.

    0 讨论(0)
  • 2021-01-23 17:12

    For anyone else that stops by; here is simple code to clear a specific range in a row if one cell contains a specific value.

    For Each cell In Range("C11:N50")
       If cell.Value2 = "0" Then
            Set cRng = Range("C" & cell.Row & ":" & "O" & cell.Row)
            ' Or Set clearRng = Range("C" & cell.Row & ":O" & cell.Row)
            cRng.Clear
       End If
    Next
    
    0 讨论(0)
提交回复
热议问题