'I want to copy a range to clipboard with criteria
I want copy a range with the following criteria
1 - Copy the entire row, including hidden columns
2 - If the Colunm "CC" has no value, them it will skip the entire row
Note Update = Sorry I forgot something, it won't always be two rows that will have data, sometimes they will have data in 3 4 5.... or in all the rows of the table
Note = My table has formulas so I don't want to mess with them, just copy the cell values
Im using this
Sub CopyVisible()
Worksheets(1).Range("B3:I13").Select
Selection.Copy
End Sub
And im getting this result
But i want this result
Im gonna copy to clipboard, then i will paste on another worksheet mannualy
With Xavier Junqué's code I'm having this result, the only problem is that he is selecting one more line
Code:
Sub CopyFilledCells()
Dim rng As Range
Set rng = Range("B3:I3")
Worksheets(1).Activate
For i = 3 To Worksheets(1).UsedRange.Rows.Count
If Worksheets(1).Range("B" & i).Value = "" Then Exit For
Next
Range(rng, rng.Offset(i - 3, 0)).Select
Selection.Copy
End Sub
Result:
Solution 1:[1]
i think the following code will do the job.
Sub CopyFilledCells()
Dim lngLastRow As Long
Sheet2.UsedRange.Clear
With Sheet1
lngLastRow = .Range("I2").End(xlDown).Row
.Range("B3:I" & lngLastRow).Copy Destination:=Sheet2.Range("A1")
End With
End Sub
Regards Bernd
Solution 2:[2]
Change instruction
Worksheets(1).Range("B3:I13").Select
to
Worksheets(1).Range("B3:I4").Select
Then, only two rows (rows# 3 and 4) between columns B and I will be copied. When pasting excel shows pasting options: select option copy only values.
Perhaps try the following:
Sub CopyFilledCells()
Worksheets(1).Activate
Worksheets(1).Range(Range("B3:I3"), Range("B3").End(xlDown)).Select
Selection.Copy
End Sub
Another try:
Sub CopyFilledCells()
Dim rng As Range
Set rng = Range("B3:I3")
Worksheets(1).Activate
For i = 3 To Worksheets(1).UsedRange.Rows.Count
If Worksheets(1).Range("B" & i).Value = "" Then Exit For
Next
Range(rng, rng.Offset(i - 3, 0)).Select
Selection.Copy
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user18083442 |
| Solution 2 |



