ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   3 VBA Conditions(last edit) (https://www.excelbanter.com/excel-programming/285241-3-vba-conditions-last-edit.html)

Todd Huttenstine[_2_]

3 VBA Conditions(last edit)
 
I have Range O2:O100 and P2:R100. The below code
looks in Range P2:R100 and if it finds a % in any of the
values, will offset into the corresponding cell in Range
O2:O100 and will put the value "percent" in the cell
itself. If it cannot find a % in any of the values in
Range P2:R100, will offset into the corresponding cell in
Range O2:O100 and will put the value "number" in the cell
itself.


Dim c As Range
For Each c In Range("O2:O100").Cells
With c
If InStr(1, .Offset(,
1).NumberFormat, "%") Or _
InStr(1, .Offset(, 2).NumberFormat, "%")
Or _
InStr(1, .Offset(, 3).NumberFormat, "%")
Then
.Value = "percent"
Else
.Value = "number"
End If
End With
Next c

Instead I need the code to perform the following. There
are a total of 3 conditions. The first condition is the %
condition which has already been addressed. The 2nd
condition is the time format. If it finds a : value in
Range P2:R100, I need it to offset into the corresponding
cell in Range O2:O100 and put the value "time" in the cell
itself.

And last, if it does not find a % or a : in any of the
value in Range P2:R100, then I need for it to offset into
the corresponding cell in Range O2:O100 and put the the
value "number" in the cell itself.



Thanx

BrianB

3 VBA Conditions(last edit)
 
The basic structure here would be :-

'----------------------------------------------
If .......... Then
'code
ElseIf ............ Then
'code
ElseIf ........... Then
'code
Else
'code
End If
'-----------------------------------------

You could presumably do a similar search for ":" to get time, or you
might find this useful :-

If IsNumber(c.Value) Then c.Value = "number"


---
Message posted from http://www.ExcelForum.com/


Todd Huttenstine[_2_]

3 VBA Conditions(last edit)
 
Thank you. This helped.


-----Original Message-----
The basic structure here would be :-

'----------------------------------------------
If .......... Then
'code
ElseIf ............ Then
'code
ElseIf ........... Then
'code
Else
'code
End If
'-----------------------------------------

You could presumably do a similar search for ":" to get

time, or you
might find this useful :-

If IsNumber(c.Value) Then c.Value = "number"


---
Message posted from http://www.ExcelForum.com/

.



All times are GMT +1. The time now is 07:32 PM.

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