VBA insert one more rule in MACRO, so Target Cells remain blank.

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings,
I have a complex Macro and it does work, however if I have a blank bell in Column B I need to ensure Column F remains blank. Now it is putting "UNIT TRNG MSN" in Column F because there is a blank cell in Column B.

The Code which works is:

Thank you,

VBA Code:
Sub Unit_Training_MSN()

    Dim FirstCharacterList As String
    Dim SecondCharacterList As String
    Dim ThirdCharacterList  As String

    FirstCharacterList = "A,B,C,E,F,G,H,I,K,L,M,N,P,Q,R,S,W,0,1,2,4,6,7,8,"
    SecondCharacterList = "E,S,U,"
    ThirdCharacterList = "N,"

    For i = 1 To Range("B" & Rows.Count).End(xlUp).Row
         If InStr(FirstCharacterList, Left(Range("B" & i), 1) & ",") <> 0 Then                    ' If 1st character Found in FirstCharacterList Then
            If InStr(SecondCharacterList, Mid(Range("B" & i), 2, 1) & ",") <> 0 Then            '   If 2nd character Found in SecondCharacterList Then
                If InStr(ThirdCharacterList, Mid(Range("B" & i), 3, 1) & ",") <> 0 Then         '       If 3rd character Found in ThirdCharacterList Then
                    If ActiveSheet.Range("F" & i) = "" Then                                     '           If the accompanying F column cell is blank Then
                        ActiveSheet.Range("F" & i) = "UNIT TRNG MSN"                                  'Make the cell = to "UNIT TRNG MSN"
                    Else                                                                        '           Else
                        ActiveSheet.Range("F" & i) = ActiveSheet.Range("F" & i) & "/UNIT TRNG MSN"    'Append "/UNIT TRNG MSN" to what is already in the F column cell
                    End If
                End If
            End If
        End If
    Next
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Its enough
VBA Code:
Sub Unit_Training_MSN()

    Dim FirstCharacterList As String
    Dim SecondCharacterList As String
    Dim ThirdCharacterList  As String

    FirstCharacterList = "A,B,C,E,F,G,H,I,K,L,M,N,P,Q,R,S,W,0,1,2,4,6,7,8,"
    SecondCharacterList = "E,S,U,"
    ThirdCharacterList = "N,"

    For i = 1 To Range("B" & Rows.Count).End(xlUp).Row
         If InStr(FirstCharacterList, Left(Range("B" & i), 1) & ",") <> 0 Then                    ' If 1st character Found in FirstCharacterList Then
            If InStr(SecondCharacterList, Mid(Range("B" & i), 2, 1) & ",") <> 0 Then            '   If 2nd character Found in SecondCharacterList Then
                If InStr(ThirdCharacterList, Mid(Range("B" & i), 3, 1) & ",") <> 0 Then         '       If 3rd character Found in ThirdCharacterList Then
                      ActiveSheet.Range("F" & i) = ActiveSheet.Range("F" & i) & "/UNIT TRNG MSN"    'Append "/UNIT TRNG MSN" to what is already in the F column cell
                End If
            End If
        End If
    Next
End Sub
 
Last edited:
Upvote 0
Its enough
VBA Code:
Sub Unit_Training_MSN()

    Dim FirstCharacterList As String
    Dim SecondCharacterList As String
    Dim ThirdCharacterList  As String

    FirstCharacterList = "A,B,C,E,F,G,H,I,K,L,M,N,P,Q,R,S,W,0,1,2,4,6,7,8,"
    SecondCharacterList = "E,S,U,"
    ThirdCharacterList = "N,"

    For i = 1 To Range("B" & Rows.Count).End(xlUp).Row
         If InStr(FirstCharacterList, Left(Range("B" & i), 1) & ",") <> 0 Then                    ' If 1st character Found in FirstCharacterList Then
            If InStr(SecondCharacterList, Mid(Range("B" & i), 2, 1) & ",") <> 0 Then            '   If 2nd character Found in SecondCharacterList Then
                If InStr(ThirdCharacterList, Mid(Range("B" & i), 3, 1) & ",") <> 0 Then         '       If 3rd character Found in ThirdCharacterList Then
                      ActiveSheet.Range("F" & i) = ActiveSheet.Range("F" & i) & "/UNIT TRNG MSN"    'Append "/UNIT TRNG MSN" to what is already in the F column cell
                End If
            End If
        End If
    Next
End Sub
[/
[/QUOTE]
I'm afraid date is stil showing up in Cell F eventhough there is nothing visiable in cells in Column B. Everything works fine. I updated an image you can see where this is happen. The strange this is on the very last date is does not do this. Where you see "No Departures" Normally there is a 13 alpha-numeric value, so if it is blank I need the Column F to be blank.

Thank you,


MSN.JPG
 
Upvote 0
Hello I did get it to work, I had to add another DIM. Works great now. Thank you,
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,590
Members
449,039
Latest member
Arbind kumar

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