ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help: Nested If/And Function formula to VB code (https://www.excelbanter.com/excel-programming/336718-help-nested-if-function-formula-vbulletin-code.html)

RAP

Help: Nested If/And Function formula to VB code
 
I have an inefficient, but working, nested if-and worksheet function formula
that I need to put into a macro. I almost got "do-looped" to death today.
Any help or direction would be most appreiciated. - Randy


Range("H11").Select (Activecell)
ActiveCell.Formula =
"=IF(AND(B11=24,B18=24,B25=24,B32=24,B39=24,B46=24 ,B53=24,B60=24),TRUE,FALSE)"

If ActiveCell = True Then

Else:


Earl Kiosterud

Nested If/And Function formula to VB code
 
RAP,

If Range("B11") = 24 And _
Range("B18") = 24 And _

RAP

Nested If/And Function formula to VB code
 
Earl,
Thank you so much for the help. I chose the Do-Loop, because I will only
have to change one variable if I add another "range of 7". I'm trying to
use/learn as many different techniques in this project as I can. Do-Loop won
the battle this time with me, but I now have a working model to examine.
Many thanks,
Randy

"Earl Kiosterud" wrote:

RAP,

If Range("B11") = 24 And _
Range("B18") = 24 And _
.
.
Range("B60") = 24 _
Then
--------------------------------------------------
Or if the number will change:

Dim CmpNum

CmpNum= 24

If Range("B11") = CmpNum And _
Range("B18") = CmpNum And _
.
.
Range("B60") = CmpNum _
Then
-----------------------------------------------------------
Or

Const CmpNum = 24

If Range("B11") = CmpNumAnd _
Range("B18") = CmpNumAnd _
.
.
Range("B60") = CmpNum _
Then
--------------------------------------------
Since they're all in column B, and are 7 cells apart, you could loop through
them:

Dim result As Boolean
Dim i As Integer
result = True

For i = 11 To 60 Step 7
Cells(i, 2).Select
If Cells(i, 2) < CmpNum Then
result = False
Exit For
End If
Next i
If result = True Then

Be aware that in any of these macro solutions, if you move the cells
(including resulting from an insert or delete), these cell references will
not move with them. You have to use range names in your macro for that to
work.
--
Earl Kiosterud
www.smokeylake.com

"RAP" wrote in message
...
I have an inefficient, but working, nested if-and worksheet function
formula
that I need to put into a macro. I almost got "do-looped" to death today.
Any help or direction would be most appreiciated. - Randy


Range("H11").Select (Activecell)
ActiveCell.Formula =
"=IF(AND(B11=24,B18=24,B25=24,B32=24,B39=24,B46=24 ,B53=24,B60=24),TRUE,FALSE)"

If ActiveCell = True Then

Else:






All times are GMT +1. The time now is 03:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com