Insert Text if first three characters are specic

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Good day,

I have a Code I know I have the right "general" idea.

I know I have the Case and listings correct, but I need the source data to be in "K6" I have Foreign Aircraft in the correct block "H8". I also know I don't need the .end(xlUp). In addition, I would like to input text in "H10" depending what the three letters are. For example "RRR" Royal Air Force would go into "H10", "CFC" would be Canadian Air Force would go into "H10" and so on. Can I have all of this in one macro or should I separate them.

Here is the macro I'm starting with.

VBA Code:
Sub Foreign_ACFT()
    Dim i As Long
    For i = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
        Select Case Left(ActiveSheet.Cells(i, 1).Value, 3)
            Case "UAF", "RRR", "IFC", "ASY", "LHO", "KAF", "CFC"
                ActiveSheet.Range("H8").Value = ActiveSheet.Range("H8").Value & " FOREIGN ACFT"
        End Select
    Next i

End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Good day,

I have a Code I know I have the right "general" idea.

I know I have the Case and listings correct, but I need the source data to be in "K6" I have Foreign Aircraft in the correct block "H8". I also know I don't need the .end(xlUp). In addition, I would like to input text in "H10" depending what the three letters are. For example "RRR" Royal Air Force would go into "H10", "CFC" would be Canadian Air Force would go into "H10" and so on. Can I have all of this in one macro or should I separate them.

Here is the macro I'm starting with.

VBA Code:
Sub Foreign_ACFT()
    Dim i As Long
    For i = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
        Select Case Left(ActiveSheet.Cells(i, 1).Value, 3)
            Case "UAF", "RRR", "IFC", "ASY", "LHO", "KAF", "CFC"
                ActiveSheet.Range("H8").Value = ActiveSheet.Range("H8").Value & " FOREIGN ACFT"
        End Select
    Next i

End Sub
I have some good news. I was able to sort it out, I just had to make a tweak or two. I ended up using two macros


VBA Code:
Sub Non_Billable()
    Dim i As Long

    For i = 1 To ActiveSheet.Cells(Rows.Count, 11).End(xlUp).Row

        Select Case Left(ActiveSheet.Cells(i + 5, 11).Value, 3)

            Case "UAF", "RRR", "IFC", "ASY", "LHO", "KAF", "CFC"

                ActiveSheet.Range("H8").Value = "FOREIGN ACFT"

        End Select

    Next i

End Sub

VBA Code:
Sub Foreign_ACFT()
    Dim i As Long

    Dim strFA As String

    For i = 1 To Cells(Rows.Count, "K").End(xlUp).Row
        strFA = Left(Cells(i, "K").Value, 3)

        If strFA = "CFC" Then Cells(i + 4, "H").Value = "Canadian Air Force"
        If strFA = "RRR" Then Cells(i + 4, "H").Value = "Royal Air Force"
         If strFA = "ASY" Then Cells(i + 4, "H").Value = "Australian Air Force"

    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,665
Members
449,114
Latest member
aides

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