vba.- Looping "if"

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hello.
VBA Code:
Sub TTT()
Dim Y&
  Dim x&
  
  For x = 2 To 9 ''ROWS
  For Y = 13 To 14 'COLUMNS - M & N
    Cells(2, 2).Formula = "=IF(" & Cells(x, Y).Address & "<" & Cells(x, Y).Address & ",TRUE, FALSE)"
    
  Next
   Next
End Sub
Trying to make it work but....
what I have and I expect is
1637920976191.png

Please, some hand here.
The first column is on M and next N and the results at B.
thanks.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi
Try
VBA Code:
Sub TTT()
Dim Y&
  Dim x&
  For x = 2 To 9 ''ROWS
    Cells(x, 2).Formula = "=IF(" & Cells(x, 13).Address & "<" & Cells(x, 14).Address & ",TRUE, FALSE)"
  Next
End Sub
Or
VBA Code:
Sub test()
Range(Cells(2, 2), Cells(9, 2)).Formula = "=IF(M2<N2,TRUE, FALSE)"
End Sub
Or
VBA Code:
Sub test()
[b2:b9].Formula = "=IF(M2<N2,TRUE, FALSE)"
End Sub
 
Last edited:
Upvote 0
Solution
You do not need the IF() function in the formula

VBA Code:
Sub test_v2()
  Range(Cells(2, 2), Cells(9, 2)).Formula = "=M2<N2"
End Sub
 
Upvote 0
Thank you Mohadin and thank you Peter, great lesson for me. happy holyday.
 
Upvote 0
You are very welcome
And Thank you for the feedback
Be happy & safe
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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