![Excel では、構造化された方法でセルに情報を追加できます。](https://rvso.com/image/1543366/Excel%20%E3%81%A7%E3%81%AF%E3%80%81%E6%A7%8B%E9%80%A0%E5%8C%96%E3%81%95%E3%82%8C%E3%81%9F%E6%96%B9%E6%B3%95%E3%81%A7%E3%82%BB%E3%83%AB%E3%81%AB%E6%83%85%E5%A0%B1%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%99%E3%80%82.png)
答え1
最終的に、いくつかのテキスト ボックスと、「データ」という別のシートの同じ列/行の値を保存するためのボタンを含むユーザー フォームを作成しました。
このようなもの:
Dim xml As String
xml = xml + "<CellDetails>"
xml = xml + " <Budget>" + UserForm1.txtBudget.Text + "</Budget>"
xml = xml + " <Comments>" + UserForm1.txtComments.Text + "</Comments>"
xml = xml + " <StartDate>" + Format(MonthView1.Value, "yyyy-mm-dd") + "</StartDate>"
xml = xml + " <EndDate>" + Format(MonthView2.Value, "yyyy-mm-dd") + "</EndDate>"
xml = xml + "</CellDetails>"
ThisWorkbook.Sheets("Data").Range(Selection.Address).Value = xml
次に、セルの「右クリック」でイベント リスナーを使用してシートからこれをトリガーし、フォーム コントロールに値を入力します。
プライベート サブ Workbook_SheetBeforeRightClick(ByVal Sh As Object、ByVal Target As Range、Cancel As Boolean)
エラー時に再開次へ
' Ctrlキーが押された場合にのみこれをトリガーします。If IsControlKeyDown() = True Then
If Not ThisWorkbook.Sheets("Data").Range(Selection.Address).Value = "" Then
Dim XDoc As MSXML2.DOMDocument
Set XDoc = CreateObject("MSXML2.DOMDocument")
XDoc.LoadXML (ThisWorkbook.Sheets("Data").Range(Selection.Address).Value)
' Setting the form values
UserForm1.txtBudget.Text = XDoc.SelectSingleNode("//CellDetails/Budget").Text
UserForm1.txtComments.Text = XDoc.SelectSingleNode("//CellDetails/Comments").Text
' Setting the dates
UserForm1.MonthView1.Value = CDate(XDoc.SelectSingleNode("//CellDetails/StartDate").Text)
UserForm1.lbStartDate = XDoc.SelectSingleNode("//CellDetails/StartDate").Text
UserForm1.MonthView2.Value = CDate(XDoc.SelectSingleNode("//CellDetails/EndDate").Text)
UserForm1.lbEndDate = XDoc.SelectSingleNode("//CellDetails/EndDate").Text
End If
UserForm1.Show
Cancel = True
End If
On Error GoTo 0
終了サブ