VBA : Placing Text in Empty Table Cells For Certainty Cells

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

VBA : Placing Text in Empty Table Cells For Certainty Cells

Post by Susanto3311 »

hi all..

how to placing text in empty table in Ms word but not all cells just certainty cells --> can skip cells contains text before
i found code but not work fully , the code can placing text for all empty cells
here code

Code: Select all

Sub ProcCells1()
    Dim tTable As Table
    Dim cCell As Cell
    Dim sTemp As String

    sTemp = "test"

    For Each tTable In ActiveDocument.Range.Tables
        For Each cCell In tTable.Range.Cells
            'An apparently empty cell contains an end of cell marker
            If Len(cCell.Range.Text) < 3 Then
                cCell.Range = sTemp
            End If
        Next
    Next
    Set oCell = Nothing
    Set tTable = Nothing
End Sub
how to make code work with step like this:
1. drag/block your table range that i want inserted text (can skip/not overwrite cells that contains text before)
2. show message box "typing or input your text that you want ......."
3. done/finish

i attachment my sample file afte running that code
anyone help me, greatly appreciated

susant
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA : Placing Text in Empty Table Cells For Certainty Cells

Post by HansV »

Code: Select all

Sub ProcCells1()
    Dim cCell As Cell
    Dim sTemp As String

    If Not Selection.Information(wdWithInTable) Then
        MsgBox "Please select cells in a table, then try again.", vbExclamation
        Exit Sub
    End If

    sTemp = InputBox("Enter some text")
    If sTemp = "" Then
        MsgBox "You didn't enter any text!", vbExclamation
        Exit Sub
    End If

    For Each cCell In Selection.Cells
        'An apparently empty cell contains an end of cell marker
        If Len(cCell.Range.Text) < 3 Then
            cCell.Range = sTemp
        End If
    Next cCell

    MsgBox "Done!", vbInformation

    Set cCell = Nothing
End Sub
Best wishes,
Hans

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA : Placing Text in Empty Table Cells For Certainty Cells

Post by Susanto3311 »

hi Hans...
AMAZING!!! Working well....thank you so much.