Adding 20 to existing value

Lukums

Board Regular
Joined
Nov 23, 2015
Messages
195
Hey guys.

Tricky one.

I have Lengths in Column A1 to A50 these lengths always vary.

I want to add 20 to whatever length is within this column.

However, I can't use any formula fields in this column as this is fed directly to our machines.

Can I somehow (magically) look at this field and add 20 via VBA? IF so, can anyone point me in that direction?

Cheers!

Luke
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Using Fluff's method from earlier today...

Code:
Sub Add20()
    With Range("A1:A50")
        .Value = Evaluate(Replace("if(@<>"""",20+@,"""")", "@", .Address))
    End With
End Sub

or

Code:
Sub add20again()
    Application.ScreenUpdating = False
    Range("K1").Value = "20"
    Range("K1").Copy
    Range("A1:A50").PasteSpecial Paste:=xlPasteAll, Operation:=xlAdd
    With Application
        .CutCopyMode = False
        Range("K1").ClearContents
        .ScreenUpdating = True
    End With
End Sub
 
Last edited:
Upvote 0
Using Fluff's method from earlier today...

Code:
Sub Add20()
    With Range("A1:A50")
        .Value = Evaluate(Replace("if(@<>"""",20+@,"""")", "@", .Address))
    End With
End Sub

or

Code:
Sub add20again()
    Application.ScreenUpdating = False
    Range("K1").Value = "20"
    Range("K1").Copy
    Range("A1:A50").PasteSpecial Paste:=xlPasteAll, Operation:=xlAdd
    With Application
        .CutCopyMode = False
        Range("K1").ClearContents
        .ScreenUpdating = True
    End With
End Sub


You beauty - big fat kisses. Thank you!
 
Upvote 0
Using Fluff's method from earlier today...

Code:
Sub Add20()
    With Range("A1:A50")
        .Value = Evaluate(Replace("if(@<>"""",20+@,"""")", "@", .Address))
    End With
End Sub
I would probably change Fluff's code to this so that any non-numeric cell would remain unchanged (instead of becoming an error)...
Code:
[table="width: 500"]
[tr]
	[td]Sub Add20()
    With Range("A1:A9")
        .Value = Evaluate(Replace("IFERROR(IF(@="""","""",@+20),@)", "@", .Address))
    End With
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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