This Macro will do what you ask.
The ID No id the sheet name.
I would however create an Index sheet to find the ID using the client name
Sub Macro1()
Start = 2
100 Sheets("name_demographics").Select
LR = Range("D65536").End(xlUp).Row
Range(Cells(Start + 1, 1), Cells(LR, 1)).Select
On Error Resume Next
Selection.Find(What:=",", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
If InStr(ActiveCell.Value, ",") > 0 Then
endrow = ActiveCell.Row - 1
Else
endrow = LR - 1
End If
Sheets("form").Select
Sheets("form").Copy Before:=Sheets(3)
ActiveSheet.Name = Sheets("name_demographics").Range("C" & Start).Value
Range("B1").Value = Sheets("name_demographics").Range("A" & Start).Value
Range("B2").Value = Sheets("name_demographics").Range("B" & Start).Value
Range("B3").Value = Sheets("name_demographics").Range("C" & Start).Value
Sheets("name_demographics").Range("D" & Start & ":E" & endrow).Copy Range("B6")
Range("B5:C" & 6 + endrow - Start).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("A1").Select
Start = endrow + 1
If Start < LR Then GoTo 100
End Sub
Bookmarks