Create Sheet from Rows in a Table

Beneindias

Board Regular
Joined
Jun 21, 2022
Messages
120
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi guys,

I'm creating a file to calculate employees wage and taxes.

In order to avoid having a table with close to 80 columns, I'm looking at having a sheet to work like a resume with taxes and amount to transfer to the employee and have individual sheets where the calculations happen.

To build this, I looked at creating a table row from each sheet, but only found a solution to create sheets from table rows. I already have VBA code that can copy a template that I have, and change the name of the sheet to the employee name.

Now, my first problem is that after my sheets are created, I can't create new sheets when I update my "resume" table. Meaning that if I have a new employee and add is name to the end of the table, my code will not create a new sheet to this new name.

Other thing, I would like to update my code so that it look for a specific header in a table instead of a cell range as I have it now.

My code looks like this:

VBA Code:
Sub Rows_to_New_Sheet()
Dim A, W_S As Worksheet, LastRow
On Error Resume Next
LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
For Each A In Range("B7:B" & LastRow)
    If A.Value <> "" Then
        Set W_S = Worksheets(A.Value)
        If W_S Is Nothing Then
            Sheets("Salários 1").Copy After:=Sheets(Sheets.Count)
            ActiveSheet.Name = Application.Proper(A.Value)
        End If
    End If
Next A
End Sub

"Salários 1" is the sheet that I'm considering as a Template.

And another thing, in the "resume" table, I have cells that will take values from this new sheets. Is there any way that this formulas will automaticaly update to seek cells in the new sheet name?
Like, if I have a formula in my table that takes a value from the sheet named "Ana", but then I create a row and sheet called "Sara" I need that formula in the new row to update to the sheet called "Sara".
Is that possible?

Thanks for the help
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I'm open to change my plan and have a vba code that creates a table row for each new sheet if it's easyer.
It was my first plan, but I couldn't find suitable code to make it hapen, so I went the other way around
 
Upvote 0
Ok, changed the formula to look for the "Name" collumn in my table instead of a range, and its copying my template sheet and changing the sheets name as intended.

Still have all the other problems, though.
 
Upvote 0
Hey guys

Updated my code a little.
Now I'm abble o put some formulas in the table when I create sheets, but, this one only puts the formula in the first row, and linking to the last sheet...
The rest of the formulas in the rows are behaving like normal rows in a table, sreating formulas to the same sheet with different rows...

My code:

VBA Code:
Sub Rows_to_New_Sheet()
Dim A, W_S As Worksheet, LastRow
On Error Resume Next
LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
For Each A In Range("Tabela10[Nome]")
    If A.Value <> "" Then
        Set W_S = Worksheets(A.Value)
        If W_S Is Nothing Then
            Sheets("Salários 1").Copy After:=Sheets(Sheets.Count)
            ActiveSheet.Name = Application.Proper(A.Value)
            Worksheets("Resumo").Select
            Range("Tabela10[Categoria]").Select
            ActiveCell = "='" & A.Value & "'!B3"
            Range("Tabela10[Valores Sujeitos a Desconto]").Select
            ActiveCell = "='" & A.Value & "'!E30"
            Range("Tabela10[Subsídio de alimentação]").Select
            ActiveCell = "='" & A.Value & "'!E34"
            Range("Tabela10[Total Remunerações]").Select
            ActiveCell = "='" & A.Value & "'!E38"
            Range("Tabela10[Totla de Descontos]").Select
            ActiveCell = "='" & A.Value & "'!J28"
            Range("Tabela10[Valor Líquido a receber]").Select
            ActiveCell = "='" & A.Value & "'!J37"
            Range("Tabela10[Transf. Bancária]").Select
            ActiveCell = "='" & A.Value & "'!J40"
            Range("Tabela10[Valores Extra]").Select
            ActiveCell = "='" & A.Value & "'!E44"
            Range("Tabela10[Total a receber]").Select
            ActiveCell = "='" & A.Value & "'!E49"
        End If
    End If
Next A
End Sub

vencimentos V3.xlsm
BCD
6NomeCategoriaValores Sujeitos a Desconto
7TonyPEDREIRO 2ª975,00
8John00,00
9Smith00,00
Resumo
Cell Formulas
RangeFormula
C7:C9C7=Smith!B3
D7:D9D7=Smith!E30


As you can see, the formulas should be:
C7 -> =Tony!B3
C8 -> =John!B3
C9 -> =Smith!B3

but, instead, I'm getting:
C7 -> =Smith!B3
C8 -> =Smith!B4
C9 -> =Smith!B5

What am I doing wrong?

Also, I still have the problem that this code only works the first time and does not update to new rows.

Thanks for all of your help
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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