Skip to main content
Commonmark migration
Source Link

###Excel VBA, 1587 bytes

Excel VBA, 1587 bytes

So it isn't really a good golf attempt, I used a standard CASE statement, which looks like:

n = InputBox("n")
Select Case n
Case "H"
m = 1
Case "He"
m = 4
Case "Li"
m = 7
......
End Select

For all 100 elements specified in the question, it will read in the abbreviation and then display its weight in a message box.
But what was interesting is instead of spending ages typing it all out, I used another bit of VBA to generate the CASE statement:

FilePath = Application.DefaultFilePath & "\code.txt"
Open FilePath For Output As #2

For i = 3 To UsedRange.Rows.Count
sentence = sentence + "Case " & Chr(34) & Cells(i, 3) & Chr(34) & vbNewLine & "m = " & Cells(i, 4) & vbNewLine
Next i

Print #2, sentence
Close #2

I copy and pasted the helpful table used in the question, the macro then reads the needed columns and pieces together the entire CASE statement used above.

I used this guide to work out how to output to a text file: http://www.homeandlearn.org/write_to_a_text_file.html

###Excel VBA, 1587 bytes

So it isn't really a good golf attempt, I used a standard CASE statement, which looks like:

n = InputBox("n")
Select Case n
Case "H"
m = 1
Case "He"
m = 4
Case "Li"
m = 7
......
End Select

For all 100 elements specified in the question, it will read in the abbreviation and then display its weight in a message box.
But what was interesting is instead of spending ages typing it all out, I used another bit of VBA to generate the CASE statement:

FilePath = Application.DefaultFilePath & "\code.txt"
Open FilePath For Output As #2

For i = 3 To UsedRange.Rows.Count
sentence = sentence + "Case " & Chr(34) & Cells(i, 3) & Chr(34) & vbNewLine & "m = " & Cells(i, 4) & vbNewLine
Next i

Print #2, sentence
Close #2

I copy and pasted the helpful table used in the question, the macro then reads the needed columns and pieces together the entire CASE statement used above.

I used this guide to work out how to output to a text file: http://www.homeandlearn.org/write_to_a_text_file.html

Excel VBA, 1587 bytes

So it isn't really a good golf attempt, I used a standard CASE statement, which looks like:

n = InputBox("n")
Select Case n
Case "H"
m = 1
Case "He"
m = 4
Case "Li"
m = 7
......
End Select

For all 100 elements specified in the question, it will read in the abbreviation and then display its weight in a message box.
But what was interesting is instead of spending ages typing it all out, I used another bit of VBA to generate the CASE statement:

FilePath = Application.DefaultFilePath & "\code.txt"
Open FilePath For Output As #2

For i = 3 To UsedRange.Rows.Count
sentence = sentence + "Case " & Chr(34) & Cells(i, 3) & Chr(34) & vbNewLine & "m = " & Cells(i, 4) & vbNewLine
Next i

Print #2, sentence
Close #2

I copy and pasted the helpful table used in the question, the macro then reads the needed columns and pieces together the entire CASE statement used above.

I used this guide to work out how to output to a text file: http://www.homeandlearn.org/write_to_a_text_file.html

Source Link

###Excel VBA, 1587 bytes

So it isn't really a good golf attempt, I used a standard CASE statement, which looks like:

n = InputBox("n")
Select Case n
Case "H"
m = 1
Case "He"
m = 4
Case "Li"
m = 7
......
End Select

For all 100 elements specified in the question, it will read in the abbreviation and then display its weight in a message box.
But what was interesting is instead of spending ages typing it all out, I used another bit of VBA to generate the CASE statement:

FilePath = Application.DefaultFilePath & "\code.txt"
Open FilePath For Output As #2

For i = 3 To UsedRange.Rows.Count
sentence = sentence + "Case " & Chr(34) & Cells(i, 3) & Chr(34) & vbNewLine & "m = " & Cells(i, 4) & vbNewLine
Next i

Print #2, sentence
Close #2

I copy and pasted the helpful table used in the question, the macro then reads the needed columns and pieces together the entire CASE statement used above.

I used this guide to work out how to output to a text file: http://www.homeandlearn.org/write_to_a_text_file.html