Created
September 17, 2017 12:59
-
-
Save normansolutions/706b114d45c1b0ef65b774b124669bcb to your computer and use it in GitHub Desktop.
Quick & Dirty Basic Excel Macro To Split Coma Separated Cells Into Columns (ideal for iSAMS sibling exports)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub Workbook_AfterSave(ByVal Success As Boolean) | |
'Crude error handling! | |
On Error Resume Next | |
siblingNameField = InputBox("Please enter the heading for the sibling names") | |
If siblingNameField = Empty Then Exit Sub | |
siblingYearField = InputBox("Please enter the heading for the sibling year group") | |
If siblingYearField = Empty Then Exit Sub | |
maximumSibling = InputBox("What is the maximum sibling count for any one family in this data set?") | |
If maximumSibling = Empty Then Exit Sub | |
firstBlank = InputBox("Enter first blank column letter?") | |
If firstBlank = Empty Then Exit Sub | |
Set nameRng = Range( _ | |
Range("A1:Z1").Find(siblingNameField).Offset(1), _ | |
Range("A1:Z1").Find(siblingNameField).Offset(1).End(xlDown)) | |
Set ageRng = Range( _ | |
Range("A1:Z1").Find(siblingYearField).Offset(1), _ | |
Range("A1:Z1").Find(siblingYearField).Offset(1).End(xlDown)) | |
'Set Values | |
nameRng.TextToColumns Destination:=Range(firstBlank + "2"), DataType:=xlDelimited, Comma:=True | |
ageRng.TextToColumns Destination:=Range(firstBlank + "2").Offset(, maximumSibling), DataType:=xlDelimited, Comma:=True | |
'Set Headings | |
For i = 1 To maximumSibling | |
Range(firstBlank + "1").Offset(, i - 1).Value = "Sibling Name " + CStr(i) | |
Range(firstBlank + "1").Offset(, i - 1 + maximumSibling).Value = "Sibling Year " + CStr(i) | |
Next i | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment