ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping with more than one condition (https://www.excelbanter.com/excel-programming/443003-looping-more-than-one-condition.html)

Carrie_Loos via OfficeKB.com

Looping with more than one condition
 
I have a very large spreadsheet that loops through cells and updates them if
they are blank. I have a new conditon to add to that where if the cell is
blank and another is not blank then move to next cell. I'm a little stuck on
how to write that part. Can I put an "And" prior to the Then?

Dim mycell As Range


For Each mycell In Range("TO_Test")
If IsEmpty(mycell) Then
mycell = "something"

End If
Next mycell

--
Message posted via http://www.officekb.com


Mike

Looping with more than one condition
 
Sub test2()
Dim mycell As Range
' If TO_Range is in column A
' Offset(0-Rows,1-Columns) will
' check 1 column to the right to if blank
For Each mycell In Range("TO_Test")
If IsEmpty(mycell) And _
IsEmpty(mycell.Offset(0, 1).Value) Then
mycell = "something"
End If
Next mycell
End Sub

"Carrie_Loos via OfficeKB.com" wrote:

I have a very large spreadsheet that loops through cells and updates them if
they are blank. I have a new conditon to add to that where if the cell is
blank and another is not blank then move to next cell. I'm a little stuck on
how to write that part. Can I put an "And" prior to the Then?

Dim mycell As Range


For Each mycell In Range("TO_Test")
If IsEmpty(mycell) Then
mycell = "something"

End If
Next mycell

--
Message posted via http://www.officekb.com

.


Carrie_Loos via OfficeKB.com

Looping with more than one condition
 
THANK YOU!

Mike wrote:
Sub test2()
Dim mycell As Range
' If TO_Range is in column A
' Offset(0-Rows,1-Columns) will
' check 1 column to the right to if blank
For Each mycell In Range("TO_Test")
If IsEmpty(mycell) And _
IsEmpty(mycell.Offset(0, 1).Value) Then
mycell = "something"
End If
Next mycell
End Sub

I have a very large spreadsheet that loops through cells and updates them if
they are blank. I have a new conditon to add to that where if the cell is

[quoted text clipped - 9 lines]
End If
Next mycell


--
Message posted via http://www.officekb.com



All times are GMT +1. The time now is 08:55 AM.

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