Condense Code?

RLJ

Active Member
Joined
Mar 15, 2011
Messages
417
Office Version
  1. 365
Platform
  1. Windows
I'm wondering if I can take the below code and condense it in some way?

Code:
Dim Doc As String

        If Me.cbLnDoc.Text = "Loan Agreement" Then
            Doc = "LA"
        End If
        If Me.cbLnDoc.Text = "Asset Summary Report" Then
            Doc = "ASR"
        End If
        If Me.cbLnDoc.Text = "Assignment of Leases & Rents" Then
            Doc = "ALR"
        End If
        If Me.cbLnDoc.Text = "Assignment of Mortgage" Then
            Doc = "AOM"
        End If
        If Me.cbLnDoc.Text = "Cash Management Agreement" Then
            Doc = "CMA"
        End If
        If Me.cbLnDoc.Text = "Comfort/Franchise Agr. (Lodging Only)" Then
            Doc = "FA"
        End If
        If Me.cbLnDoc.Text = "Deed of Trust" Then
            Doc = "DOT"
        End If
        If Me.cbLnDoc.Text = "Environmental Indemnity Agreement" Then
            Doc = "EIA"
        End If
        If Me.cbLnDoc.Text = "Escrow Agreement" Then
            Doc = "EA"
        End If
        If Me.cbLnDoc.Text = "Guaranty Agreement" Then
            Doc = "GA"
        End If
        If Me.cbLnDoc.Text = "Management Agreement" Then
            Doc = "MA"
        End If
        If Me.cbLnDoc.Text = "Other; Please Describe" Then
            Doc = "_"
        End If
        If Me.cbLnDoc.Text = "Post Closing Letter/Agreement" Then
            Doc = "PCA"
        End If
        If Me.cbLnDoc.Text = "Promissory Note" Then
            Doc = "Note"
        End If
        If Me.cbLnDoc.Text = "Reserve Agreement" Then
            Doc = "RA"
        End If
        If Me.cbLnDoc.Text = "Side Letter" Then
            Doc = "SLTR"
        End If

This works for what I need it to do, but in my quest to learn more about vba, I'm wondering if there is a better/more code condensed format.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
CASE statements are a bit shorter for this type of thing (see: MS Excel: CASE Statement (VBA)).

So your code would look like this:
Code:
    Dim Doc As String


    Select Case Me.cbLnDoc.Text
        Case "Loan Agreement"
            Doc = "LA"
        Case "Asset Summary Report"
            Doc = "ASR"
        Case "Assignment of Leases & Rents"
            Doc = "ALR"
        Case Is = "Assignment of Mortgage"
            Doc = "AOM"
        Case "Cash Management Agreement"
            Doc = "CMA"
        Case Is = "Comfort/Franchise Agr. (Lodging Only)"
            Doc = "FA"
        Case "Deed of Trust"
            Doc = "DOT"
        Case "Environmental Indemnity Agreement"
            Doc = "EIA"
        Case "Escrow Agreement"
            Doc = "EA"
        Case "Guaranty Agreement"
            Doc = "GA"
        Case "Management Agreement"
            Doc = "MA"
        Case "Other; Please Describe"
            Doc = "_"
        Case "Post Closing Letter/Agreement"
            Doc = "PCA"
        Case "Promissory Note"
            Doc = "Note"
        Case "Reserve Agreement"
            Doc = "RA"
        Case "Side Letter"
            Doc = "SLTR"
        ' What to return if none of the values above are found
        Case Else
            Doc = ""
    End Select
 
Upvote 0
Thanks, I read the link you provided.
 
Upvote 0

Forum statistics

Threads
1,213,556
Messages
6,114,284
Members
448,562
Latest member
Flashbond

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