VBA deplace a cells into column A

cazdealer

Board Regular
Joined
Mar 12, 2011
Messages
96
Hi,
I need to create a VBA procedure that will cut and paste (or deplace) all my filled cells into column A.

For exemple, I have a lot of empty cell in the range A1 to BF999 but also have cells with data in them.

I would like to take every cell that have data in that range and put them from cell A1 to A999999. (in whatever order). And do nothing with the empty cells.

how could I do that?

thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Maybe the "SpecialCells" method?

Gary

Code:
Public Sub Test()

Dim oCurrCell As Range
Dim oCell As Range
Dim oData As Range

Set oCurrCell = ActiveSheet.Range("A1")

Set oData = ActiveSheet.Range("A1:BF999").SpecialCells(xlCellTypeConstants)

For Each oCell In oData
    oCurrCell.Value = oCell.Value
    oCell.Interior.ColorIndex = 3
    Set oCurrCell = oCurrCell.Offset(1, 0)
Next oCell

Set oData = ActiveSheet.Range("A1:BF999").SpecialCells(xlCellTypeFormulas)

For Each oCell In oData
    oCurrCell.Value = oCell.Value
    oCell.Interior.ColorIndex = 4
    Set oCurrCell = oCurrCell.Offset(1, 0)
Next oCell

End Sub
 
Upvote 0
it doesnt works...
it buggs at line:

Set oData = ActiveSheet.Range("A1:BF999").SpecialCells(xlCellTypeFormulas)
 
Upvote 0
Apparently you have no formulas. Try with formula section disabled like this:

Gary

Code:
Public Sub Test()

Dim oCurrCell As Range
Dim oCell As Range
Dim oData As Range

Set oCurrCell = ActiveSheet.Range("A1")

Set oData = ActiveSheet.Range("A1:BF999").SpecialCells(xlCellTypeConstants)

For Each oCell In oData
    oCurrCell.Value = oCell.Value
    oCell.Interior.ColorIndex = 3
    Set oCurrCell = oCurrCell.Offset(1, 0)
Next oCell

'Set oData = ActiveSheet.Range("A1:BF999").SpecialCells(xlCellTypeFormulas)
'
'For Each oCell In oData
'    oCurrCell.Value = oCell.Value
'    oCell.Interior.ColorIndex = 4
'    Set oCurrCell = oCurrCell.Offset(1, 0)
'Next oCell


End Sub
 
Upvote 0
BTW, if you did have formulas and they were in column A data might be lost (overwritten) by the first loop. It would be better to insert a new column in front of column A and change the range(s) from ActiveSheet.Range("A1:BF999") to ActiveSheet.Range("B1:BG999").

Gary
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top