Re-alignment of data
-
- 2StarLounger
- Posts: 183
- Joined: 19 Feb 2016, 16:54
- Location: Veraval, India
Re-alignment of data
Hi,
I have attached a sample file. I have a situation wherein the data is available with me in the shape and format as available in "Base file" tab. I want to re-align it and bring it in a shape and format as presented in "Result tab". Can anyone think of any trick or shortcut or macro. There are 600 such line items - sample file contains only two and manually doing it will consume almost a day.
Thanks in advance.
I have attached a sample file. I have a situation wherein the data is available with me in the shape and format as available in "Base file" tab. I want to re-align it and bring it in a shape and format as presented in "Result tab". Can anyone think of any trick or shortcut or macro. There are 600 such line items - sample file contains only two and manually doing it will consume almost a day.
Thanks in advance.
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 79324
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 5StarLounger
- Posts: 608
- Joined: 27 Jun 2021, 10:46
Re: Re-alignment of data
Your 'Base file' sheet seems to be inconsistent
-
- 5StarLounger
- Posts: 611
- Joined: 14 Nov 2012, 16:06
Re: Re-alignment of data
Code: Select all
Sub M_snb()
sn = Sheet2.Cells(1).CurrentRegion
ReDim sp(UBound(sn) - 1, UBound(sn, 2) - 1)
For j = 1 To UBound(sn) - 1 Step 2
sp(n, 0) = sn(1, 2)
sp(n, 1) = sn(j + 1, 2)
sp(n, 2) = sn(j + 2, 2)
sp(n + UBound(sn) \ 2, 0) = sn(1, 3)
sp(n + UBound(sn) \ 2, 1) = sn(j + 1, 3)
sp(n + UBound(sn) \ 2, 2) = sn(j + 2, 3)
n = n + 1
Next
Sheet1.Cells(2, 6).Resize(UBound(sp) + 1, UBound(sp, 2) + 1) = sp
End Sub
-
- 2StarLounger
- Posts: 183
- Joined: 19 Feb 2016, 16:54
- Location: Veraval, India
-
- 2StarLounger
- Posts: 183
- Joined: 19 Feb 2016, 16:54
- Location: Veraval, India
-
- 5StarLounger
- Posts: 821
- Joined: 24 Jan 2010, 15:56
Re: Re-alignment of data
For example row 4 says UniqueID in column A but actually contains dates.
Regards,
Rory
Rory
-
- 2StarLounger
- Posts: 183
- Joined: 19 Feb 2016, 16:54
- Location: Veraval, India
Re: Re-alignment of data
Oh i see, that's an input error. Unique ID comes only once and dates and units are repeated. Check now, have fixed that.
You do not have the required permissions to view the files attached to this post.
-
- 5StarLounger
- Posts: 821
- Joined: 24 Jan 2010, 15:56
Re: Re-alignment of data
Here's a power query method.
You do not have the required permissions to view the files attached to this post.
Regards,
Rory
Rory
-
- 5StarLounger
- Posts: 611
- Joined: 14 Nov 2012, 16:06
-
- 2StarLounger
- Posts: 183
- Joined: 19 Feb 2016, 16:54
- Location: Veraval, India
Re: Re-alignment of data
Hi snb,snb wrote: ↑01 Dec 2023, 08:55Why ignoring https://eileenslounge.com/viewtopic.php ... 87#p312487 ?
Tried it, it worked on my sample file. However not working on the actual file with 600 records ! Not able to understand why.
-
- 2StarLounger
- Posts: 183
- Joined: 19 Feb 2016, 16:54
- Location: Veraval, India
-
- 5StarLounger
- Posts: 821
- Joined: 24 Jan 2010, 15:56
Re: Re-alignment of data
It's all in the sample workbook. You can just replace the table with a table of your actual data.
Regards,
Rory
Rory
-
- 2StarLounger
- Posts: 183
- Joined: 19 Feb 2016, 16:54
- Location: Veraval, India
Re: Re-alignment of data
Allright, thanks a lot. This is really helpful and time saving
-
- 5StarLounger
- Posts: 652
- Joined: 18 Jan 2022, 15:59
- Location: Re-routing rivers, in Hof, Beautiful Bavaria
Re: Re-alignment of data
Hello
Here’s another alternative VBA way, using the non looping pretty one line arrOut()=Index(arrIn(), Rws(), Clms()) way
This should do it for the supplied test data
Some explanations for how I did that
here
and
here
It is possibly easy to adapt that to the full data or any data if the typical format is known and regular. If you want help with that then let me see the full data so that I am sure what the typical base worksheet might look like.
_.__________
To test, run that macro on your returned file attached to this post. (There are a couple of extra worksheets to help with the explanations)
Alan
Here’s another alternative VBA way, using the non looping pretty one line arrOut()=Index(arrIn(), Rws(), Clms()) way
This should do it for the supplied test data
Code: Select all
Sub makroo() ' https://eileenslounge.com/viewtopic.php?f=27&t=40371 https://www.excelfox.com/forum/showthread.php/2837-Appendix-Thread-App-Index-Rws()-Clms()-Majic-code-line-Codings-for-other-Threads-Tables-etc-)/page53#post19567 https://www.excelfox.com/forum/showthread.php/2837-Appendix-Thread-App-Index-Rws()-Clms()-Majic-code-line-Codings-for-other-Threads-Tables-etc-)/page53#post19568
' Unique ID
Let Worksheets.Item(1).Range("A2:A27") = Application.Index(Worksheets.Item(2).Range("B1:C1"), 1, Evaluate("IF({1},INT(((Row(1:26)-1)/13))+1)"))
' Date & Units
Let Worksheets.Item(1).Range("B2:C27") = Application.Index(Worksheets.Item(2).Range("B2:C27"), Evaluate("(((Row(1:26)-1)*2)+COLUMN(A:B))-((IF({1},INT((ROW(1:26)-1)/13)+1))-1)*26"), Evaluate("IF({1},INT((ROW(1:26)-1)/13)+1)"))
End Sub
here
and
here
It is possibly easy to adapt that to the full data or any data if the typical format is known and regular. If you want help with that then let me see the full data so that I am sure what the typical base worksheet might look like.
_.__________
To test, run that macro on your returned file attached to this post. (There are a couple of extra worksheets to help with the explanations)
Alan
You do not have the required permissions to view the files attached to this post.
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(
-
- 2StarLounger
- Posts: 183
- Joined: 19 Feb 2016, 16:54
- Location: Veraval, India
Re: Re-alignment of data
Thanks DocAElstein !