I want to add a column named serial number and fill in that column till n where n is number of count of items in the adjacent column.

sachin772020

New Member
Joined
Aug 19, 2020
Messages
2
Office Version
  1. 2007
Hi All,

I want to add a column named serial number and fill in that column till n where n is number of count of items in the adjacent column. Please suggest a VBA code for this.


PFB, I have shown the raw data which we get from the tool and the required format.

The number of rows will be dynamic everyday. I have also attached the screenshot for the same.


Raw DataRequired Data
ItemRankSr. No.ItemRankRankRank
A210
450 (-1%)
1A210450(-1%)
B20
450 (-1%)
2B20450(-1%)
C230
500 (1%)
3C230500-1%
D960
480 (-9%)
4D960480(-9%)






Regards, Sachin
 

Attachments

  • Capture.PNG
    Capture.PNG
    19 KB · Views: 4

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Book5
ABCDE
1IndexItemRank.1Rank.2Rank.3
21A210450(-1%)
32B20450(-1%)
43C230500(1%)
54D960480(-9%)
Sheet2


Here is the Mcode from Power Query.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Rank", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Rank", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Rank.1", "Rank.2", "Rank.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Rank.1", Int64.Type}, {"Rank.2", Int64.Type}, {"Rank.3", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type1", "Index", 1, 1, Int64.Type),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"Index", "Item", "Rank.1", "Rank.2", "Rank.3"})
in
    #"Reordered Columns"
 
Upvote 0
Hi alansidman, The number of rows will be dynamic everyday. I needed a vba macro code for the same. I have shown the raw data and the required output.
 
Upvote 0
Using Power Query, if you update the original data set and click on the refresh button, then the data in the output will automatically update for you.

EDIT. Just noticed that you are using Excel 2007. This solution will not work for you as PQ was not introduced until Excel 2010. My apologies.
 
Upvote 0
Cross posted VBA macro code to add a column named serial number and fill in that column till n where n is number of count of items in the adjacent column.

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,214,790
Messages
6,121,607
Members
449,037
Latest member
Arbind kumar

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