incrementing a column

geversud

Board Regular
Joined
Jul 17, 2002
Messages
181
Is there anyway to increment the value in a range without explicitly looping?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
Well, without knowing what you want, you could use Paste Special, Add or Multiply, depending on what you want/have/need.
 

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
geversud,
You could add the incrementation value to a blank cell. Copy it, then on the values you want to increment just do a paste special, change the operation to add, and press OK. This will increment all values in the paste range by the orginal copied value.

HTH
Cal
 

geversud

Board Regular
Joined
Jul 17, 2002
Messages
181
Basically, I have a worksheet full of parts. In one column is the level of assembly and in the other the partnumber. (level of assembly reads as number 1 for the top most part with all the subcomponents of the assembly as level 2 and and sub components of 2 parts as level 3 and so on) There are many of these worksheets and the column representing the level of assembly is offset by 1 (for example the second part reads as level 1 but should be level 2) this is for all the parts. So in short, what would be the most efficient way to increment this column by 1.
 

geversud

Board Regular
Joined
Jul 17, 2002
Messages
181
This works well but I would like to avoid having to assign a value to a cell then copy it and paste it. I have to execute this operation hundreds of times and would like not to disrupt the integrity of the sheets beyond incrementing those values in column. Is there another way I can accomplish this strictly in the background through code?
 

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
Code:
Sub Increment()
Dim OldValue as String

OldValue = Range("A1").value
Range("A1").value = 1
Range("A1").copy
Range("b1",range("B65535").end(xlup)).pastespecial xlPasteValues,xlPasteSpecialOperationAdd
Range("A1").value =OldValue
End Sub

This will increment all values in column B by 1, each time it is executed.

HTH
Cal
 

geversud

Board Regular
Joined
Jul 17, 2002
Messages
181
Thanks for your help this definitely works out. And I am assuming that there is no other way to do this, less explicitly looping.
 

Forum statistics

Threads
1,147,844
Messages
5,743,510
Members
423,800
Latest member
IuneKeiki

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