Adding a mirror to matching cells

luizmoraes

New Member
Joined
Jul 25, 2019
Messages
6
I have a VBA code that creates a new line in the worksheet. My problem is: cell B3 has a name that changes from time to time, When running the VBA and creating the new line, I need to compare the value on B3 with the Table, and insert (inside the new line), a Mirror to the table with the match value. In this case, if I update the value inside the table, the value will be updated inside all the lines. Anyone help?

For more information:
I have two worksheets, "Home" and "Info".
Inside "Home", there is a table. I already have a VBA code that add's a new line to this table every time I click the button. Above that table, in B3, I have a text that I typed manually, let's say "Address One".
Inside the another worksheet "Info", I have a table named "Tabela5", and on that table there is a lot of cells, including the same "Address One".
So, I need a VBA code that when i'm inserting a new line, it will look the value from B3 ("Address One"), search "Tabela5" what cell have the same value, and insert a mirror to that cell.
So, inside "Home" it will have a new line on the table, and it will have the value <code style="margin: 0px; padding: 1px 5px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; vertical-align: baseline; box-sizing: inherit; background-color: rgb(239, 240, 241); white-space: pre-wrap;">='Info'!I7</code> , for example. In that case, I7 is the cell with "Address One" value, exacly the same as B3 "Home".
The most close I did was this code, but getting error:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub InsertNewLine()
'
' InsertNewLine Macro
'

'
Dim cell As Range
Dim list As ListObject
Dim config As Worksheet
Set config = Sheets("Home")
Set list = config.ListObjects("Tabela5")
'search in any cell of the data range of excel table
Set cell = list.DataBodyRange.Find(What:=Range("B3"))
If list = Value <> "" Then
k
= list
c
= Application.Match(k, Sheets("Home").Range("E5"), 0)
Rows
("5:5").Select
Selection
.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

If cell Is Nothing Then

Else
config
.Hyperlinks.Add Anchor:=cell, _
Address
:="", _
SubAddress
:="Home!B3" & c, _
TextToDisplay
:=k
End If
End If
End Sub</code>I'm getting error on:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">config.Hyperlinks.Add Anchor:=cell, _
Address
:="", _
SubAddress
:="Home!B3" & c, _
TextToDisplay
:=k</code>Thank you in advance
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I'm confused, You have 2 sheets and 2 tables.

In the description you say:
Inside the another worksheet "Info", I have a table named "Tabela5"

But in the code is different:

Code:
[COLOR=#101094][FONT=Consolas][FONT=inherit]Set[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] config [/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]=[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] Sheets[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]"[/FONT][/FONT][/COLOR][COLOR=#ff0000][FONT=Consolas][FONT=inherit]Home[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]"[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit])[/FONT][/FONT][/COLOR]
[COLOR=#101094][FONT=Consolas][FONT=inherit]Set[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] list [/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]=[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] config[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit].[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]ListObjects[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]"[/FONT][/FONT][/COLOR][COLOR=#ff0000][FONT=Consolas][FONT=inherit]Tabela5[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]"[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit])
[/FONT][/FONT][/COLOR]
 
Upvote 0
I got that code from Internet and I adapted it, but something went wrong. I really don't know what is

Tabela5 is under Info. The another table is on Home.
 
Upvote 0
I got that code from Internet and I adapted it, but something went wrong. I really don't know what is

Tabela5 is under Info. The another table is on Home.

Better explain by example what you have, what your sheets or tables really are called. You can upload images or a file to the cloud. Then explain what you need.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top