What is wrong with this IF/Then/Else loop

Palerock68

New Member
Joined
Apr 20, 2018
Messages
6
So, I want Excel to go through each cell in the column I and if the length of the cell contents is more than zero, go through the next lines and change the content accordingly... but if the content is not listed and still the length of the current content is more than Zero... just change it to 3.2. But if the length of the content is zero, just go to next cell.

But I cannot get any of the combinations to work correctly.

This leaves the cell untouched, even if the length is more than zero, but the character found is not listed:

For f = 7 To LastRow
If Len(Cells(f, 9)) > 0 Then
If Cells(f, 9) = 2 Then Cells(f, 9) = "'3.2"
If Cells(f, 9) = 1 Then Cells(f, 9) = "'3.1"
If Cells(f, 9) = "T" Then Cells(f, 9) = "'3.1"
If Cells(f, 9) = "-" Then Cells(f, 9).ClearContents
If Cells(f, 9) = Chr(42) Then Cells(f, 9) = Chr(42)
Else
If Len(Cells(f, 9)) > 0 Then Cells(f, 9) = "'3.2"
End If
Next f

And the following fills all cells with 3.2, regardless of the cells content length:

For f = 7 To LastRow
If Len(Cells(f, 9)) > 0 Then
If Cells(f, 9) = 2 Then Cells(f, 9) = "'3.2"
If Cells(f, 9) = 1 Then Cells(f, 9) = "'3.1"
If Cells(f, 9) = "T" Then Cells(f, 9) = "'3.1"
If Cells(f, 9) = "-" Then Cells(f, 9).ClearContents
If Cells(f, 9) = Chr(42) Then Cells(f, 9) = Chr(42)
Else
Cells(f, 9) = "'3.2"
End If
Next f


And the following works like the first one, it leaves the not listed characters untouched:

For f = 7 To LastRow
If Len(Cells(f, 9)) > 0 Then
If Cells(f, 9) = 2 Then Cells(f, 9) = "'3.2"
If Cells(f, 9) = 1 Then Cells(f, 9) = "'3.1"
If Cells(f, 9) = "T" Then Cells(f, 9) = "'3.1"
If Cells(f, 9) = "-" Then Cells(f, 9).ClearContents
If Cells(f, 9) = Chr(42) Then Cells(f, 9) = Chr(42)
ElseIf Len(Cells(f, 9)) > 0 Then Cells(f, 9) = "'3.2"
End If
Next f

Could anybody help a bit?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Code:
For f = 7 To LastRow
    If Len(Cells(f, 9).Value) > 0 Then
        Select Case Cells(f, 9).Value
            Case 2
                Cells(f, 9).Value = "'3.2"
            Case 1
                Cells(f, 9).Value = "'3.1"
            Case "T"
                Cells(f, 9).Value = "'3.1"
            Case "-"
                Cells(f, 9).ClearContents
            Case "*"
                Cells(f, 9).Value = "*"
            Case Else
                Cells(f, 9).Value = "'3.2"
        End Select
    End If
Next f

WBD
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

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