Shift data to left

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,

I have got data in column D:G, and need shift data results in columns J:M,

Example data.


Book1
ABCDEFGHIJKLMNO
1
2
3
4
5
612341234
72|2|12|2|1
8
92|2|12|2|1
10
111|1|11|1|1
121|1|21|1|11|1|21|1|1
131|1|11|1|1
141|2|12|1|11|2|12|1|1
151|1|11|1|1
161|1|11|1|11|1|11|1|11|1|11|1|1
171|2|12|1|11|2|12|1|1
181|1|21|1|2
191|1|21|1|21|1|21|1|2
201|1|11|1|11|1|11|1|1
211|1|21|1|2
221|1|11|1|11|1|11|1|1
231|1|11|1|11|1|11|1|1
241|1|11|1|11|1|11|1|11|1|11|1|1
251|2|21|1|11|1|11|2|21|1|11|1|1
261|1|11|1|11|1|11|1|11|1|11|1|1
271|1|11|1|1
281|2|11|1|11|2|11|1|1
292|1|12|1|1
30
312|2|11|1|12|1|12|2|11|1|12|1|1
321|2|22|1|11|2|22|1|1
331|1|11|1|1
341|1|12|1|21|1|12|1|2
351|2|11|2|1
361|2|11|2|1
37
381|1|11|1|21|1|11|1|2
391|2|21|2|2
40
411|1|11|1|1
421|2|11|1|11|2|11|1|1
431|1|11|1|21|2|21|1|11|1|21|2|2
44
451|2|11|1|11|2|11|1|1
461|1|11|1|11|1|11|1|1
471|1|11|1|1
481|1|11|1|11|1|11|1|1
491|1|11|1|11|1|11|1|1
501|1|11|1|21|1|11|1|2
511|1|11|1|1
521|1|11|2|11|1|11|1|11|2|11|1|1
531|1|11|1|1
541|1|11|1|12|1|21|1|11|1|12|1|2
551|1|11|1|1
562|1|12|1|1
57
581|2|21|1|11|2|21|1|1
591|1|21|1|11|1|21|1|1
601|2|21|1|11|2|21|1|1
611|1|11|2|11|1|11|2|1
622|1|12|1|1
631|1|11|2|11|1|11|2|1
641|1|11|1|12|1|21|1|11|1|11|1|12|1|21|1|1
651|2|11|2|22|2|11|1|11|2|11|2|22|2|11|1|1
661|2|21|1|11|1|11|2|21|1|11|1|1
671|1|12|2|11|1|12|2|1
681|1|11|1|21|1|11|1|2
692|1|12|1|1
70
71
Sheet1


Thank you in advance

Regards,
Kishan
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You're not giving us much to go on...and the data isn't even the same, so "shift" might not be the right word, seems to me.
 
Upvote 0
You're not giving us much to go on...and the data isn't even the same, so "shift" might not be the right word, seems to me.
Hi jproffer, you can see the data column D:G are split in 4 columns, what I want alien them to left as shown in the column J:M, and remove the empty space in betweens of the data

Regards,
Kishan
 
Upvote 0
Hi, I did found code which delete empty cells and shift data to left but in the column D:G it self.

But I want to keep the original data in to columns D:G
And get shifted data in to new columns J:M

Is it possible?

It can be VBA or formula solution.

Regards,
Kishan
 
Last edited:
Upvote 0
I understand what you meant now by "shift"...so maybe you could copy your original data to J:M and then run the code you found on those columns to remove the spaces and fill data to the left...

?? Would that work?

If you need help with that, and so we're not reinventing the wheel you've already found, maybe post what you have that moves the data to the empty cells and we can add to it to accomplish what you want.
 
Upvote 0
I understand what you meant now by "shift"...so maybe you could copy your original data to J:M and then run the code you found on those columns to remove the spaces and fill data to the left...

?? Would that work?

If you need help with that, and so we're not reinventing the wheel you've already found, maybe post what you have that moves the data to the empty cells and we can add to it to accomplish what you want.
HI jproffer,
Here is the code, which align the data to left and delete the blank cells in the columns D:G
Code:
Sub ShiftLeft()
Dim rng As Range
With ActiveSheet
    For Each cll In Intersect(.UsedRange, .Range("D:G")).Cells
        If Len(cll.Value) = 0 Then Set rng = Union(cll, IIf(rng Is Nothing, cll, rng))
    Next cll
End With
rng.Delete xlShiftToLeft
End Sub

But I want to keep column D:G data remain original and show align data in columns in J:M

Does it is possible?

Regards,
Kishan
 
Upvote 0
Try this for results starting "J7"
Code:
[COLOR="Navy"]Sub[/COLOR] MG31May00
[COLOR="Navy"]Dim[/COLOR] Ray, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] col [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
Ray = Range("D7:G70")
ReDim nray(1 To UBound(Ray, 1), 1 To UBound(Ray, 2))
[COLOR="Navy"]For[/COLOR] n = 1 To UBound(Ray, 1)
 col = 0
 [COLOR="Navy"]For[/COLOR] Ac = 1 To UBound(Ray, 2)
    [COLOR="Navy"]If[/COLOR] Not IsEmpty(Ray(n, Ac)) [COLOR="Navy"]Then[/COLOR]
        col = col + 1
        nray(n, col) = Ray(n, Ac)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Ac
[COLOR="Navy"]Next[/COLOR] n
Range("J7").Resize(UBound(Ray, 1), UBound(Ray, 2)) = nray
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this for results starting "J7"
Code:
[COLOR=navy]Sub[/COLOR] MG31May00
[COLOR=navy]Dim[/COLOR] Ray, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Ac [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] col [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
Ray = Range("D7:G70")
ReDim nray(1 To UBound(Ray, 1), 1 To UBound(Ray, 2))
[COLOR=navy]For[/COLOR] n = 1 To UBound(Ray, 1)
 col = 0
 [COLOR=navy]For[/COLOR] Ac = 1 To UBound(Ray, 2)
    [COLOR=navy]If[/COLOR] Not IsEmpty(Ray(n, Ac)) [COLOR=navy]Then[/COLOR]
        col = col + 1
        nray(n, col) = Ray(n, Ac)
    [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR] Ac
[COLOR=navy]Next[/COLOR] n
Range("J7").Resize(UBound(Ray, 1), UBound(Ray, 2)) = nray
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
Excellent!! Mike, Thank you for your help and time.

Appreciate it. Performing as treat.

Regards,
Kishan :)
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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