2

I have a one sheet with a column which ranges from C2 till C6115. In that range there are many empty cells. I want to copy the filled cells only into a seperate sheet using VB in excel 2007. Can anyone give me a general code that can help me perform that?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Satbir
  • 23
  • 1
  • 5

1 Answers1

1
Sub copy()
Dim i As Long
Dim cell As Range
i = 1
For Each cell In Sheets(1).Range("c2:c6115")
    If Not IsEmpty(cell) Then
        Sheets(2).Range("c" & i).Value = cell.Value
        i = i + 1
    End If
Next cell
End Sub
Nicola Cossu
  • 54,599
  • 15
  • 92
  • 98
  • This code copys to the proper destination but it doesnt copy the correct column, it copied random information from column B. – Satbir Jun 06 '11 at 14:42
  • I tested it before write here and it copies not empty cells within the range c2:c6115 from sheet1 into column c of sheet 2. I don't know why you have this weird behaviour. – Nicola Cossu Jun 06 '11 at 15:59