VBA to increase numbers by 1

Yamasaki450

Board Regular
Joined
Oct 22, 2021
Messages
71
Office Version
  1. 2021
Platform
  1. Windows
Hi everyone...

I would like to increase all numbers in range B2:N3 by one. Like shown on screenshot.
Is anyone able to write VBA code for this? I already tried this with formula bellow but it only works on positive numbers and not on negatives. My range is of data is quite long in some cases and i need to drag formula across the whole range every time... so VBA code would be much easier...

Or maybe there is another way to do this?

Formula i tried
Excel Formula:
=TEXTJOIN("-",,FILTERXML("<k><m>"&SUBSTITUTE(A4,"-","</m><m>")&"</m></k>","//m")+1)
 

Attachments

  • Clipboard01.png
    Clipboard01.png
    22.2 KB · Views: 6

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Have you ever tried the Copy/Paste Special/Add feature, which makes this extremely easy?

Simply put a 1 in any blank cell outside of the range you want to add it to.
Then, select that cell and click "Copy".
Then, select the entire range you wish to update, and right-click and go to Paste Special -> Add and press OK.

That will add that number to every cell in your range at once!
You could also probably automate these steps using VBA, though if your range can change, you would either want to select that from the start, or prompt the user for it.
 
Upvote 0
How about
Fluff.xlsm
BCDEFGHIJKLMN
1
27-32-22-2935-65-486532-172-41262103
38-19-21-2525-43-415924-147-38233100
4
5
6
7
8
9
108-33-23-3036-66-496633-173-42263104
119-20-22-2626-44-426025-148-39234101
Main
Cell Formulas
RangeFormula
B10:N11B10=B2:N3+SIGN(B2:N3)
Dynamic array formulas.
 
Upvote 0
Solution
Ah, I missed the fact that it appears that they want to ADD one to positive numbers, and SUBTRACT one from negative numbers.
(The title is a little misleading, but the image clarifies that).

So my solution would not do that, but Fluff's should.
 
Upvote 0
Without a formula or VBA, you could just put 1 in a cell. Copy it. Select your Entire Range, right click, Click on Paste Special Add.

@Fluff, does that work with Excel 2021?
 
Upvote 0
Without a formula or VBA, you could just put 1 in a cell. Copy it. Select your Entire Range, right click, Click on Paste Special Add.

@Fluff, does that work with Excel 2021?
Scott, you are making the exact same mistake I did. I originally recommended the same thing, but upon further inspection, saw that was NOT what they are after.
Have a look at my two posts above, and look closely at the original image, which includes desired output.

For example, adding 1 to -32 results in -31, when it appears that they actually want -33.
 
Upvote 0
How about
=B2:N3+SIGN(B2:N3)
This does exactly what i need. Thanks a lot. Again:)

Have you ever tried the Copy/Paste Special/Add feature, which makes this extremely easy?

Simply put a 1 in any blank cell outside of the range you want to add it to.
Then, select that cell and click "Copy".
Then, select the entire range you wish to update, and right-click and go to Paste Special -> Add and press OK.

That will add that number to every cell in your range at once!
You could also probably automate these steps using VBA, though if your range can change, you would either want to select that from the start, or prompt the user for it.
Without a formula or VBA, you could just put 1 in a cell. Copy it. Select your Entire Range, right click, Click on Paste Special Add.

@Fluff, does that work with Excel 2021?
This will come useful too in some cases later on...

Thanks for your help guys. Have a nice day...
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,876
Messages
6,181,520
Members
453,050
Latest member
Obil

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