A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
This is only possible if you refer to the objects and use there properties to get the correct location.
Andreas.
Sub Macro11_AK()
Dim WB As Workbook
Dim CB As CheckBox
Dim R1 As Range, R2 As Range, R1Last As Range, R2Last As Range
'Refer to cell B2 in Sheet1
Set R1 = Sheets("Sheet1").Range("B2")
'Find the last used cell from the bottom
Set R1Last = R1.Offset(Rows.Count - R1.Row).End(xlUp)
'Insert a column
R1.EntireColumn.Insert
'After that R1 refers to cell C2, refer to the cells on the left side
Set R1 = R1.Offset(0, -1)
Set R1Last = R1Last.Offset(0, -1)
'Do the same in Scenic Stock
'Set R2 = Sheets("Scenic Stock").Range("Table14[[#Headers],[ProjectB]]")
Set R2 = Sheets("Scenic Stock").Range("E3")
Set R2Last = R2.Offset(Rows.Count - R2.Row).End(xlUp)
R2.ListObject.ListColumns.Add Position:=5
Set R2 = R2.Offset(0, -1)
Set R2Last = R2Last.Offset(0, -1)
'Open the workbook
Set WB = Workbooks.Open("C:\Users\Lane\Documents\Thesis\April14-01.xlsm")
'Copy some values into Sheet1
Sheets("Platform Materials").Range("B3:B12").Copy
R1.Offset(1).PasteSpecial Paste:=xlPasteValues
R1 = Sheets("Info Bank").Range("B1")
'Close it, reject changes
WB.Close False
Application.CutCopyMode = False
'Insert the checkbox, same position and size as the cell
With R2
Set CB = .Parent.CheckBoxes.Add(.Left, .Top, .Width, .Height)
End With
'Setup the checkbox
With CB
'Check it
.Value = xlOn
'Refer to the last cell in Sheet1
.LinkedCell = R1Last.Address(External:=True)
'Remove the caption
.Characters.Text = ""
'Make it smaller
CB.Width = CB.Height
'Move it to the right side of the cell minus size of the dropdown
CB.Left = R2.Left + R2.Width - CB.Width - 12
End With
'Copy the header
R2.Value = R1.Value
'Create the formula
R2.Offset(1, 0).Formula = _
"=IF(" & R1Last.Address(External:=True) & "," & _
R1.Offset(1).Address(0, 0, External:=True) & ",0)"
'Copy it down
Range(R2.Offset(1, 0), R2Last).FillDown
End Sub