Home > Blockchain >  VBA to change a list of numbers with decimals to a list of integers only
VBA to change a list of numbers with decimals to a list of integers only

Time:06-28

So I came across this problem of a number list having decimal numbers in between integers, and I would like to change them to a list of just integers.

So there is a list that looks like this :

  • 1
  • 1
  • 2
  • 2.1
  • 2.2
  • 3
  • 3
  • 3.1
  • 3.1
  • 4

I want to keep the group of the same numbers but just want to renumber them with integers, so the end result would look something like this:

  • 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 5
  • 6
  • 6
  • 7

Or this is a screenshot of an example,

My Goal

After some trial and errors, I ask for help.

The logic of renumbering is

  1. Numerical order
  2. Rows of the same numbers need to have the same number

And of course, this is just a small example of the actual task I need to do that has like over thousands of entries.

What macro would be able to do that?

CodePudding user response:

You need a formula, like this one:

=IF(A1=A2,B1,B1 1)

The results are like the following screenshot:

enter image description here

For your information: "B1" equals =A1 (so you must start with an integer), "B2" equals the mentioned formula and you just drag it down.

  • Related