Forum Discussion
Luma1
Mar 09, 2024Copper Contributor
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...
- Mar 10, 2024
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.
Luma1
Mar 10, 2024Copper Contributor
I did not get this to work, though good to learn more about Excel. See my response to Sergei with some more explanation.
Thanks
Thanks
NikolinoDE
Mar 10, 2024Gold Contributor
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.
- Luma1Mar 10, 2024Copper ContributorI think this could work but I am using to much force for my problem, I will have to simplify my workprocess.
Thanks for your effort