Forum Discussion

Luma1's avatar
Luma1
Copper Contributor
Mar 09, 2024
Solved

Copy data into worksheet with hidden rows but want only visible cells to recieve...

I am moving data from one Excel file to another by copying it, but in the receiving Excel workbook, some lines are filtered away and hidden (part of a long series of historical data but no longer rec...
  • NikolinoDE's avatar
    NikolinoDE
    Mar 10, 2024

    Luma1 

    I'm still not sure what exactly is meant (the translation software is probably overwhelmed), but here is a VBA code as an example with a test file.

     

    Sub CopyVisibleCellsOnly()
        Dim sourceRange As Range
        Dim targetRange As Range
        Dim cell As Range
        
        ' Set the source range to be copied (adjust as needed)
        Set sourceRange = ThisWorkbook.Sheets("Quelldaten").Range("A1:A100")
        
        ' Set the target range where data should be pasted (adjust as needed)
        Set targetRange = ThisWorkbook.Sheets("Empfangsbereich").Range("A1:A100")
        
        ' Loop through each cell in the source range
        For Each cell In sourceRange
            ' Check if the corresponding row in the target range is visible
            If Not targetRange.Rows(cell.Row).Hidden Then
                ' If visible, copy the value from the source cell to the target cell
                targetRange.Cells(cell.Row, 1).Value = cell.Value
            End If
        Next cell
    End Sub

     

    Hope this is what you want.

Resources