Saturday, December 8, 2012

How to Shift Up Data in between Empty Cells in a Desired Column using Excel VBA Macro

Excel VBA Macro to Shift Up Data which in between Empty Cells in a Desired Column
'This Macro is Very Useful to Shift Up The Data Of a Desired Column , Where Data Is In Between Empty Cells.
'Data In Between Empty Cells Means Some Cells Having Data and Some Cells are Empty
'This Macro Does not Delete any Cells so that the Data in Other Columns Would Not get Disturb.
'This Macro Shifts Up Data From All Cells(1048576 Rows)of a Desired Column
Sub Shift_Data_Up()
Dim X As Long
Dim Y As Long
Dim z As Long

Dim C As Long
On Error GoTo Err1:

C = InputBox("Enter Desired Column No.In Which Data To Be Shift UP", _
"Shift Up Data In Between Empty Cells", _
"Enter Here As 1 or 2 or 3.....")

z = Cells(1, C).EntireColumn.Cells.COUNT

'Z Is The Total No.Of Rows(1048576)
'If You Know The Row Range(Eg: 100) Define It So That You Can Speed Up Macro Process

Y = 0

For X = 1 To z  'Instead of 'Z' You can give Your desired Range
If Cells(X, C) <> "" Then
Y = Y + 1
Sheets(1).Cells(Y, C) = Sheets(1).Cells(X, C)
'Shifts Up Data From Desired Column of Sheet1
End If
Next X

'Range(Cells(Y + 1, C), Cells((Y + 1) + (Z - (Y + 1)), C)).Clear
'Clears the Data In following Cells of Shifted Data

MsgBox "Data Success Fully Shifted Up", vbInformation, "Macro Process Completed"

Err1:

End Sub

Thanks,Tamatam

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog