I have set up a macro that creates a new worksheet that lists out names of all the worksheets in to two columns (B2:B20) and (C2:C20) and add checkmarks next to them. What I want to accomplish is if you check mark worksheets in columns B5, B6, B7 and check mark worksheet in C2.. I want specific columns in the three worksheets from B5, B6, B7 to be added to a specific column in the worksheet referred to in C2.
The summing of the columns will always be the same, for example the worksheet it needs to be added to in C2 the column should look like this
Cell AG29(in worksheet referred to in C2) = "= Cell AG129(in worksheet referred to in B5) + Cell AG129(in worksheet referred to in B6) + Cell AG129(in worksheet referred to in B7)"
What will be different is which worksheets the data is being pulled from and which worksheet is it being added to
This is the code I have that creates the new worksheet:
Sub AddColumns()
ActiveWorkbook.Sheets.Add.Name = "Worksheet_Names"
With ThisWorkbook.Worksheets("Worksheet_Names")
.Select
.Activate
End With
Selection.Insert
For i = 1 To Sheets.Count
Cells(i, 2) = Sheets(i).Name
Next i
With Range("A1")
.EntireRow.Insert
End With
Range("B1:B2000").SpecialCells(xlCellTypeConstants).Select
Selection.Copy
Range("F2").Select
ActiveSheet.Paste
For Each cell In Range("B2:B50").SpecialCells(xlCellTypeConstants)
With ActiveSheet.CheckBoxes.Add(cell.Left, _
cell.Top, cell.Width, cell.Height)
.LinkedCell = cell.Offset(, -1).Address(External:=True)
.Interior.ColorIndex = xlNone
.Caption = ""
End With
Next
For Each cell In Range("F2:F50").SpecialCells(xlCellTypeConstants)
With ActiveSheet.CheckBoxes.Add(cell.Left, _
cell.Top, cell.Width, cell.Height)
.LinkedCell = cell.Offset(, -1).Address(External:=True)
.Interior.ColorIndex = xlNone
.Caption = ""
End With
Next
With Range("B2:F50")
.EntireColumn.AutoFit
.HorizontalAlignment = xlRight
End With
Range("B1").Select
ActiveCell.FormulaR1C1 = "Add"
Application.Run "OnEntryCell"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Add to"
Application.Run "OnEntryCell"
Range("B2").Select
End Sub
The summing of the columns will always be the same, for example the worksheet it needs to be added to in C2 the column should look like this
Cell AG29(in worksheet referred to in C2) = "= Cell AG129(in worksheet referred to in B5) + Cell AG129(in worksheet referred to in B6) + Cell AG129(in worksheet referred to in B7)"
What will be different is which worksheets the data is being pulled from and which worksheet is it being added to
This is the code I have that creates the new worksheet:
Sub AddColumns()
ActiveWorkbook.Sheets.Add.Name = "Worksheet_Names"
With ThisWorkbook.Worksheets("Worksheet_Names")
.Select
.Activate
End With
Selection.Insert
For i = 1 To Sheets.Count
Cells(i, 2) = Sheets(i).Name
Next i
With Range("A1")
.EntireRow.Insert
End With
Range("B1:B2000").SpecialCells(xlCellTypeConstants).Select
Selection.Copy
Range("F2").Select
ActiveSheet.Paste
For Each cell In Range("B2:B50").SpecialCells(xlCellTypeConstants)
With ActiveSheet.CheckBoxes.Add(cell.Left, _
cell.Top, cell.Width, cell.Height)
.LinkedCell = cell.Offset(, -1).Address(External:=True)
.Interior.ColorIndex = xlNone
.Caption = ""
End With
Next
For Each cell In Range("F2:F50").SpecialCells(xlCellTypeConstants)
With ActiveSheet.CheckBoxes.Add(cell.Left, _
cell.Top, cell.Width, cell.Height)
.LinkedCell = cell.Offset(, -1).Address(External:=True)
.Interior.ColorIndex = xlNone
.Caption = ""
End With
Next
With Range("B2:F50")
.EntireColumn.AutoFit
.HorizontalAlignment = xlRight
End With
Range("B1").Select
ActiveCell.FormulaR1C1 = "Add"
Application.Run "OnEntryCell"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Add to"
Application.Run "OnEntryCell"
Range("B2").Select
End Sub