Forum

Macro to format dat...
 
Notifications
Clear all

Macro to format data

5 Posts
4 Users
0 Reactions
84 Views
(@frothx99)
Posts: 2
New Member
Topic starter
 

I have a need to have a macro to format and build out data. My original data will look like the following. I have attached a sample to this post.:

Code ID
100a
10118
10128
12042
12686
100c

100i
10083
10190
10192
10216
10227

What I need to happen is that the code value is copied to the left cell to that of an ID number. The number of rows can change based upon the output of data to ecel. The need to flatten the data is so that I can have build pivot charts and tables. In some cases there will be a Code and no ID's to go with it. In those cases a empty row will be displayed under the Code. That row would need to be removed.

Copy data down in a macro I have done, but it stops when it gets to the next Code.

Any help would be appreciated. I cannot change the original format of the data so need to address it after it gets into Excel.

 
Posted : 20/01/2023 7:49 pm
Riny van Eekelen
(@riny)
Posts: 1186
Member Moderator
 

You didn't attach a file. Please try again and press "Start upload" before submitting your reply.

 
Posted : 21/01/2023 2:55 am
(@frothx99)
Posts: 2
New Member
Topic starter
 

I have attached it here. Thanks for the follow up.

 
Posted : 22/01/2023 2:24 pm
Alan Sidman
(@alansidman)
Posts: 222
Member Moderator
 

If I am understanding your needs correctly, then an easy means is with Power Query versus VBA

Mcode

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Filled Down" = Table.FillDown(Source,{"Code"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([ID] null))
in
#"Filtered Rows"

 
Posted : 22/01/2023 10:58 pm
(@james1989)
Posts: 5
Active Member
 

Hi,

Do you need to fill in Blanks in Column A ...???

Sub FilinBlanks()
Range("A2:A14").SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
End Sub

 
Posted : 28/01/2023 4:52 am
Share: