PDA

View Full Version : Copying from only cells with data in range



Ray.Mason
06-20-2012, 12:42 PM
I am trying to develop a macro that copies cell data in a column range. However in this column range other cells are empty and I want the macro to ignore all empty cells. Ideally the macro will look into eg cell C9 then copy, then go into another cell within the range that contains data, copy until end of loop.

The code I have below works but selects individual cells within range.
Range("A8").Activate Do If ActiveCell.Value = "STOP" Then Exit Do ActiveCell.Offset(1, 0).Copy Loop

Can you please help me with ways I can amend my code to loop cell to cell that contain data and individual copy these cells. I will paste these into some bookmark (not an issue at the moment)

Many thanks!

CodeNinja
06-20-2012, 12:51 PM
Ray.Mason,
Not quite sure what you want to do, but I hope this is helpful....



Sub test()
Dim rng As Range
Set rng = Sheet1.Range("A1:A11")
For Each cell In rng
If cell.Value = "STOP" Then
Exit Sub
Else
cell.Offset(0, 1) = cell.Value
End If
Next cell

End Sub

Ray.Mason
06-20-2012, 01:33 PM
Thanks codeNinja.

What I'm basically trying to do is starting from cell A8 to cell that contains STOP, go cell by cell and each cell that contains data copy and paste into some word bookmark.

Ray.Mason
06-20-2012, 02:02 PM
This has worked. Many thanks codeNinja for your contribution. I used the specialCells feature.

:)