Insert a column and paste value to last used row

Dokat

Active Member
Joined
Jan 19, 2015
Messages
304
Office Version
  1. 365
Hi,

I have a data table where I'd like to insert a column B and paste "Channel" in Cell B1 and "Commercial" from cell B2 to last used row in column C. I have below code where it lets me insert a column however returns "Compile error" when running the second code. Appreciate any? Thanks

1647607688665.png


VBA Code:
Sub Addcolumn()

Columns(2).EntireColumn.Insert
Columns(2).ClearFormats

End Sub
Sub Paste()

    Dim LastRow As Long
    Dim Ws As Worksheet
    Set Ws = Worksheets("Sheet1")
            LastRow = Ws.Cells(Ws.Rows.Count, 1).End(xlUp).Row
            Ws.Range("B2:B" & LastRow).Copy Destination:="Commercial"
            Ws.Range("B1").Copy Destination:="Channel"

End Sub
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
solved my own problem

Below code worked for me

VBA Code:
Sub Addcolumn()

Columns(2).EntireColumn.Insert
Columns(2).ClearFormats

Dim LastRow As Long
Dim Ws As Worksheet
Dim range As String
Dim r As range
Dim s As range
range = "Commercial"
header = "Channel Breakout"
Set Ws = ThisWorkbook.Worksheets("Sheet1")
LastRow = Ws.Cells(Ws.Rows.Count, 3).End(xlUp).Row
Set r = Ws.range("B2:B" & LastRow)
Set s = Ws.range("B1")
s = header
r = range
          
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,174
Members
449,071
Latest member
cdnMech

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