Hello,
1. Copy the procedure named TableNames in a new module in the copy of your file.
2 . Run the procedure.
3. See the name manager (Ctrl + F3)
4. Copy the procedure named UpdateDataInSheets in a module 1 (delete previous version).
5. Run the procedure.
Don't forget to check the results !...
Regards.
Option Explicit
'Rename all tables with smart names
Public Sub TableNames()
Dim wb As Workbook
Dim ws As Worksheet
Dim lo As ListObject
Dim txt As String
Set wb = ThisWorkbook
For Each ws In wb.Worksheets
Select Case ws.Name
'sheets to ignore
Case "B_Confin":
Case Else:
'sheets to be processed
txt = Replace(ws.Name, " ", vbNullString)
Set lo = ws.Cells(1).ListObject
lo.DisplayName = txt
Set lo = ws.Cells(6).ListObject
lo.DisplayName = txt & "2"
End Select
Next ws
End Sub
Public Sub UpdateDataInSheets()
Dim loData As ListObject, lo As ListObject
Dim Cell As Range, r As Range
Dim n, arr(1)
Dim dt As Double
Dim nm As String
Set loData = Range("Business_Confidence").ListObject
If loData.DataBodyRange Is Nothing = False Then
For Each Cell In loData.ListColumns(1).DataBodyRange
dt = Cell.Offset(, 1).Value
nm = VBA.Replace(Cell.Value, " ", "")
On Error Resume Next
Set lo = Range(nm).ListObject
On Error GoTo 0
If Not lo Is Nothing Then
n = Application.Match(dt, lo.ListColumns(2).DataBodyRange, 0)
If IsError(n) Then
arr(0) = Cell.Offset(, 1).Value
arr(1) = Cell.Offset(, 2).Value
With lo
'If .InsertRowRange Is Nothing Then
Set r = .HeaderRowRange.Cells(1).Offset(.ListRows.Count + 1)
'Else
'Set r = .InsertRowRange.Cells(1)
'End If
End With
r.Offset(, 1).Resize(, 2).Value = arr
End If
End If
Next Cell
End If
End Sub