Update entire column with existing cell value to become "value * 20% + 10"

weijianhk

New Member
Joined
Feb 27, 2015
Messages
18
Hi Experts,

Currently I faced a problem with my codes, but let me explain what I am trying to achieve here.
So I have a worksheet that have many columns and headers, I would like to update the entire column(s) where the header name contains "iot".
So the entire column already has values in each cell, and that value should be updated with a formula i.e. value * 20% + 10.
In the example below, the results would then be updated as shown below.

I have my 2 liner codes below, but somehow I can't figure that out. I would appreciate if any experts could guide me in the right direction please. Thank you!

Before
iot1 | bs1 | iot2 | bs2
3 | 2 | 5 | 2

After
iot1 | bs1 | iot2 | bs2
13.6| 2 | 16 | 2


For i = ActiveSheet.Columns.Count To 1 Step -1
If InStr(1, Cells(2, i), "iot") Then Columns(i).EntireColumn.Value = Columns(i).EntireColumn.Value * 0.15 + 10
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Not quite sure what you are after as you say you want to multiply by 20% & add 10, but your code is *0.15+10 and your results are +20% +10
This gives the same values as you have shown
Code:
Sub addpercent()
   Dim i As Long, lr As Long
   lr = Range("B" & Rows.Count).End(xlUp).Row
   For i = Cells(2, Columns.Count).End(xlToLeft).Column To 1 Step -1
      If Cells(2, i) Like "iot*" Then
         With Range(Cells(3, i), Cells(lr, i))
            .Value = Evaluate(Replace("if(@<>"""",@*1.2+10,"""")", "@", .Address))
         End With
      End If
   Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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