For loop for a column

jebenexcel

Board Regular
Joined
Mar 16, 2018
Messages
59
hey guys,

I need a macro to make all data in one column of variable size do this:
if data in a cell of the column M is bigger than 900, subtract 900.
Afterwards, if the numbers 33 and 34 pop up, they should be changed to 13 and 14, respectively.

This is pretty basic stuff, but I don't know the syntax, can you guys help?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi. See if this code does what you need.
Code:
Sub ChangeValues()
 Dim rngM As Range
  For Each rngM In Range("M1:M" & Cells(Rows.Count, "M").End(3).Row)
   If rngM.Value = 933 Then rngM.Value = 13
   If rngM.Value = 934 Then rngM.Value = 14
   If rngM.Value > 900 Then rngM.Value = rngM.Value - 900
  Next rngM
End Sub
 
Last edited:
Upvote 0
How about
Code:
Sub ChangeM()
   With Range("M2", Range("M" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("if(@=933,13,if(@=934,14,if(@>900,@-900,@)))", "@", .Address))
   End With
End Sub
 
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