Active X button, VBA to copy format and formula of above cells.

Winklevos

New Member
Joined
Oct 28, 2014
Messages
1
I'm trying to make the button find the last instance of a non-empty cell in column B, then select the row between (B:L) from the last non-empty cell in column B. Copy the format and formula in the selection then insert a new row below and insert the format and formula. The reason I'm not using a table is that the tables are in weekly periods and I need to be able to add more to a week without having to manually move the other weeks down.

I know little about VBA so I'm having trouble.
I have:

Private Sub CommandButton1_Click()

' Go to last cell
Range("B19").Select
Selection.End(xlDown).Select
LastCell = [A65536].End(xlUp).Offset(-1, 0).Address
Range(LastCell).Select

' Enter new line
Selection.EntireRow.Insert Shift:=xlUp, CopyOrigin:=xlFormatFromLeftOrAbove <- This line is a problem.

Dim oCell As Range
While (oCell.Offset(-1, 0).Value = "") ' If the cell above is not empty
oCell.Offset(-1, 0).Copy Destination:=oCell ' Copy the formula from the cell above
Selection.Offset(-1, 0).Select ' Move one cell to the right

Wend
End Sub

Firstly it isn't finding the last non-empty cell in column B, rather I'm specifying a cell. Secondly it doesn't seem to enter a new line.

Can anyone help. Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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