This little piece will take the rest of the querystring before the first # . Before using this, test it very well for errors in the newly created querystring.
Sub Get_Comment()
'WHERE TimeStampUTC > #YYYY-MM-DD HH:MM:SS# And TimeStampUTC <= #YYYY-MM-DD HH:MM:SS#
'comment of cell
Dim mycomment As String
'starting date, starting time
Dim mydate1 As String, mytime1 As String
'ending date, ending time
Dim mydate2 As String, mytime2 As String
'show current comment
MsgBox ActiveCell.Comment.Text
'clear variable that will hold comment
mycomment = vbNullString
'declare the comment of active cell to variable mycomment
mycomment = ActiveCell.Comment.Text
'some split stuff to get date1 into variable, also rest of
'split ups that you want to do
mydate1 = Split(Split(ActiveCell.Comment.Text, "#")(1), " ")(0)
mytime1 = Split(Split(ActiveCell.Comment.Text, "#")(1), " ")(1)
mydate2 = Split(Split(ActiveCell.Comment.Text, "#")(3), " ")(0)
mytime2 = Split(Split(ActiveCell.Comment.Text, "#")(3), " ")(1)
mydate1 = Application.InputBox("Give new start date" & vbCrLf & _
"Use the format YYYY-MM-DD ...", "Start date", mydate1, Type:=2)
mytime1 = Application.InputBox("Give new start time ..." & vbCrLf & _
"Use the format HH:MM:SS ...", "Start time ...", mytime1, Type:=2)
mydate2 = Application.InputBox("Give new ending date" & vbCrLf & _
"Use the format YYYY-MM-DD ...", "Ending date", mydate2, Type:=2)
mytime2 = Application.InputBox("Give new ending time" & vbCrLf & _
"Use the format HH:MM:SS ...", "Ending time", mytime2, Type:=2)
'build new query that you want to store in comment
'*** old part for query
'mycomment = "WHERE TimeStampUTC > #" & mydate1 & " " & mytime1 & _
"# And TimeStampUTC <= #" & mydate2 & " " & mytime2 & "#"
'Split gives part before first # then add new dates and times and try
'to put a correct query in the comment. Still not bulletproof but you don't
'have to enter the comment manually
'*** new part that takes part of query before first #
mycomment = Split(ActiveCell.Comment.Text, "#")(0) & "#" & mydate1 & " " & mytime1 & _
"# And TimeStampUTC <= #" & mydate2 & " " & mytime2 & "#"
'show old comment one last time
MsgBox ActiveCell.Comment.Text
'delete the old comment
ActiveCell.Comment.Delete
'put new comment in the place
ActiveCell.AddComment mycomment
'show new comment
MsgBox ActiveCell.Comment.Text
End Sub
Charlize