VBA Shift all data to left alternative Delete

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone need help to shifting all data in range to far left leaving no blank cells. I need an alternative to .Delete shift:=xlToLeft as this effects all data to the right.

my range("AG2:AZ1000") I do not want to effect the data to the right of column AZ.

ex. below Orange Highlight is my data and Green Highlight is what I want the outcome to be

Book2
AGAHAIAJAKAL
1D1D2D3D4D5D6
27/277/287/31
3
4
57/57/77/8
67/147/177/18
77/37/9
8
9
10
11
12
13
14D1D2D3D4D5D6
157/277/287/31
16
17
187/57/77/8
197/147/177/18
207/37/9
21
22
23
24
25
Sheet1



any help is greatly appreciated.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this:
VBA Code:
Sub hajiali_1()
Dim i As Long, j As Long, k As Long
Dim va

    va = Range("AG2:AZ1000")
    ReDim vb(1 To UBound(va, 1), 1 To UBound(va, 2))
    
    For i = 1 To UBound(va, 1)
       k = 0
           For j = 1 To UBound(va, 2)
               If Len(va(i, j)) <> 0 Then
                   k = k + 1
                   vb(i, k) = va(i, j)
               End If
           Next
    Next
    
    Range("AG2").Resize(UBound(vb, 1), UBound(vb, 2)) = vb
End Sub
 
Upvote 0
Solution
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,215,278
Messages
6,124,023
Members
449,139
Latest member
sramesh1024

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