Code to Update if Positive

EssKayKay

Board Regular
Joined
Jan 5, 2003
Messages
221
Office Version
  1. 2007
Platform
  1. Windows
Is it possible to update a column of IF statements to the "number" where the IF statement returns a positive value, otherwise leave it as an IF statement (probably via VBA code)?

This is an abridged version of the IF statement “=IF(C33=$K$9,$K$10,0)”.

Thanks,
SKK
 
Last edited by a moderator:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
How about, something like
Code:
Sub EssKayKay()
   Dim Cl As Range
   
   For Each Cl In Range("L2", Range("L" & Rows.count).End(xlUp))
      If Cl > 0 Then Cl.Value = Cl.Value
   Next Cl
End Sub
 
Upvote 0
Thanks Fluff for your response. Please bear with me a bit but what am I to do with this code? I assume I have to define the range but where does that go?
 
Upvote 0
What range do you want it to work on?
 
Upvote 0
In that case, try
Code:
Sub EssKayKay()
   Dim Cl As Range
   
   For Each Cl In Range("I33:I1500")
      If Cl > 0 Then Cl.Value = Cl.Value
   Next Cl
End Sub
 
Upvote 0
In that case, try
Code:
Sub EssKayKay()
   Dim Cl As Range
   
   For Each Cl In Range("I33:I1500")
      If Cl > 0 Then Cl.Value = Cl.Value
   Next Cl
End Sub

Excellent that appears to be doing it. I added some code to run your code if the value in a specific cell is updated. It also appears to be working. Here's what I added.

'====================================
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$K$10" Then
EssKayKay
End If
End Sub
'=====================================

Again, thank you very much Fluff....
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,405
Messages
6,119,315
Members
448,886
Latest member
GBCTeacher

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