Macro to add columns from different worksheets based on True/False

uapak90

New Member
Joined
Jul 8, 2011
Messages
3
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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,224,504
Messages
6,179,142
Members
452,892
Latest member
JUSTOUTOFMYREACH

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