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
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