Want to copy a string of text and a range of cells

Job ID: 32733472

Budget: $10 – $30 AUD

Hi all,

I had some code it isn't pretty but it does the job. I want a string of text that is added at the start of the copied cells in excel.

Text: The following people need to complete a detention

then have the sorted and list attached below here

"'
Sub CopyDataWithText()
'
' Macro2 Macro
'

'

Dim MyString As String
Dim myrange As Range

' Text I want
MyString = "The following student need to complete a detention. Those that are highlighted, further consequences will apply if not completed today."

' Sorting Code
ActiveWorkbook.Worksheets("Detention").ListObjects("Table5").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("Detention").ListObjects("Table5").Sort.SortFields. _
Add2 Key:=Range("Table5[_studentform]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Detention").ListObjects("Table5").Sort.SortFields. _
Add2 Key:=Range("Table5[_StatusCaption]"), SortOn:=xlSortOnValues, Order _
:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Detention").ListObjects("Table5").Sort.SortFields. _
Add2 Key:=Range("Table5[_fullname]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Detention").ListObjects("Table5").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

' Select the cells I want to copy
Range("F2:S2").Select
Range(Selection, Selection.End(xlDown)).Select
' Selection.Copy

' this is where my code falls apart
Set myrange = Selection
Dim mytext As DataObject
mytext = MyString & vbNewLine & myrange
mytext.PutInClipboard

End Sub
"'
Related categories: Visual Basic Excel Software Architecture