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.
SergeiBaklan
Mar 09, 2024MVP
How do you do that?
If I have source data as
filter on first column hiding b
copy all above and paste into another file, result is
Luma1
Mar 10, 2024Copper Contributor
Thanks, but I need to explain further.
I may have been unclear.
The source data can be copied just like that, e g value in cell A1, A2, A3, A4
The receiving area is the issue and has rows 1,2,3,4,5 and 6 where row 2 and 3 are hidden and not supposed to receive any value e g Row one= A1, Row 3 = A2, Row 3 = A3 etc. No value to hidden rows 3 and 3
I need Excel to jump the hidden rows.
- SergeiBaklanMar 10, 2024MVP
I see, that opposite situation.
If to skip both hidden rows in target and related values in source that could be done with keyboard. Otherwise with script.