VBA: add +1 in column A

Laurens1

New Member
Joined
Dec 9, 2016
Messages
31
Hi Guys,

I want to add a number to each row, starting on A3 with 0, A4 1, A5 2, etc. Until the last row in column B is reached.

Can you guys help me?
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,916
Office Version
  1. 365
Platform
  1. Windows
Is there already something in those cells, or are they blank?
So are you wanting to add to what is currently in those cells, or just override them with 0,1,2,...?
 

Laurens1

New Member
Joined
Dec 9, 2016
Messages
31
cells in column A are empty. iI want to count the filled cells in column B, starting from B3 till the last row
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,916
Office Version
  1. 365
Platform
  1. Windows
Try this:
Code:
    Dim rng As Range
    Set rng = Range("A3:A" & Cells(Rows.Count, "B").End(xlUp).Row)
    rng.Formula = "=ROW()-3"
    rng.Value = rng.Value
Without VBA, simply enter this formula in cell A3:
Code:
=ROW()-3
and double-click to autofill down to the last row.
 

Laurens1

New Member
Joined
Dec 9, 2016
Messages
31
It must be VBA... I try to keep the macro of somebody else alive. Some inheritance from someone who knew what he did. :biggrin:

But it works, thanks a lot!!!
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,916
Office Version
  1. 365
Platform
  1. Windows
You are welcome!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,606
Messages
5,597,134
Members
414,128
Latest member
Jorglo

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
Top