VBA & Macro Problems

Save Text to an Excel Record by Name and Date

Khadija KhanKhadija Khan Dec 2, 2026 869 views

Question details

Save entered text in the Excel record that matches a selected name and date.

How to Save Text to an Excel Record by Name and Date
Product
Microsoft Excel
Device & OS
not provided
Scenario
A user selects a name and date, enters text, and wants to post it to the corresponding row in a record table.
Observed behavior
Excel formulas can retrieve matching data but cannot permanently write user input into another cell.
Before you start

Use desktop Excel for the VBA method; Excel for the web cannot run VBA macros. Make sure each name and date combination identifies only one record, and that dates are stored as recognizable Excel dates.

Solution 1Recommended

Use a VBA button to post text to the matching record

Use this method when you want a button to find the matching name and date and write the entered text automatically.

The macro below overwrites the existing text in the matching row. It stops without writing if there is no match or more than one match.

1
Create the record table

On a worksheet named Records, create columns named Name, Date, and Text. Select the range, choose Insert > Table, and name the table RecordsTable on the Table Design tab.

2
Set up the entry cells

On a worksheet named Entry, use B2 for the name, B3 for the date, and B4 for the text to save. Optionally, select B2 and use Data > Data Validation > List to provide valid names.

3
Add the macro

Open Developer > Visual Basic, choose Insert > Module, and paste this code: Sub PostText() Dim ws As Worksheet, tbl As ListObject, r As ListRow Dim entryName As String, entryDate As Date, entryText As String Dim matches As Long, target As Range Set ws = ThisWorkbook.Worksheets("Entry") Set tbl = ThisWorkbook.Worksheets("Records").ListObjects("RecordsTable") If IsError(ws.Range("B2").Value) Or IsError(ws.Range("B3").Value) Or IsError(ws.Range("B4").Value) Then MsgBox "Check the entry cells for errors." Exit Sub End If entryName = Trim(CStr(ws.Range("B2").Value)) entryText = CStr(ws.Range("B4").Value) If entryName = "" Or Trim(entryText) = "" Or Not IsDate(ws.Range("B3").Value) Then MsgBox "Enter a name, a valid date, and text." Exit Sub End If entryDate = DateValue(CDate(ws.Range("B3").Value)) For Each r In tbl.ListRows If Not IsError(r.Range.Cells(1, tbl.ListColumns("Name").Index).Value) And Not IsError(r.Range.Cells(1, tbl.ListColumns("Date").Index).Value) Then If StrComp(Trim(CStr(r.Range.Cells(1, tbl.ListColumns("Name").Index).Value)), entryName, vbTextCompare) = 0 Then If IsDate(r.Range.Cells(1, tbl.ListColumns("Date").Index).Value) Then If DateValue(CDate(r.Range.Cells(1, tbl.ListColumns("Date").Index).Value)) = entryDate Then matches = matches + 1 Set target = r.Range.Cells(1, tbl.ListColumns("Text").Index) End If End If End If End If Next r If matches <> 1 Then MsgBox "Expected one matching record; found " & matches & "." Exit Sub End If target.NumberFormat = "@" target.Value = entryText MsgBox "Text saved to the matching record." End Sub

4
Assign and run the macro

On the Entry sheet, insert a shape from Insert > Shapes, right-click it, and choose Assign Macro > PostText. Enter a name, date, and text in B2:B4, then click the shape.

5
Save the workbook

Choose File > Save As and select Excel Macro-Enabled Workbook (.xlsm) to retain the VBA code. When reopening the file, enable macros only if you trust the workbook.

Use a VBA button to post text to the matching record
Matching behavior: Names are matched without regard to capitalization, and the date comparison ignores time. If duplicate records exist, resolve them before posting.
Work with records in WPS

Update name-and-date records in WPS Spreadsheets

Open your workbook in WPS Spreadsheets, filter the record table by name and date, and enter the text in the matching row. This is a manual alternative to the Excel VBA posting button.

  1. 1. Open the workbook: In WPS Spreadsheets, choose Open and select the workbook containing your records.
  2. 2. Turn on filters: Select the header row and choose Data > Filter if filter arrows are not already visible.
  3. 3. Find the record: Use the Name and Date filter arrows to display the desired record, and check that only one row matches.
  4. 4. Save the text: Click the matching row's Text cell, enter the text, and choose File > Save.
Find records using name and date filtersOpen and edit Microsoft Excel XLSX filesWork with a familiar spreadsheet interfaceUse WPS Office for free
microsoft office alternative - wps office

Frequently Asked Questions

Can an Excel formula write text into another cell?

No. A formula returns a result in its own cell; it cannot permanently write user input to another cell. Use VBA to automate the write or edit the target cell manually.

What happens if two rows have the same name and date?

The sample macro reports the number of matches and does not write to either row. Correct the duplicate records in the Records table before clicking the posting button again.

Why doesn't the macro find a date that looks correct?

The entry and record dates must be recognizable Excel dates, not unrecognized text. Check the cells on the Entry and Records sheets and re-enter the date if needed.

Will posting text add it to what is already in the record?

No. The sample macro replaces the existing value in the matching row's Text cell. Change the macro if you need to append text or keep a separate history of entries.

Can I use the VBA button in Excel for the web?

No. Open the macro-enabled workbook in desktop Excel to run the VBA button. In Excel for the web, you can filter the table and update the matching cell manually.