VBA to get last row and column, then copy and paste

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
Somehow I posted before asking my question: so here it is. As you can see by the title, I am trying to find the last row and column used, select a specific range, then copy and paste to the next available column but I am getting a host of errors. Below is my code, if you could help that would be great!

Sub newEntry()


Dim lastCol As Integer
Dim startCol As Integer
Dim newStartCol As Integer
Dim lastRow As Integer
Dim cRng As Range
Dim pRng As Range
Dim sht As Worksheet



Set sht = ThisWorkbook.Worksheets("2015")


lastCol = sht.Cells(2, sht.Columns.Count).End(x1ToLeft).Column



startCol = lastCol - 56
newStartCol = lastCol + 1


lastRow = .Cells(sht.Rows.Count, 3).End(x1Up).Row




MsgBox lastCol
MsgBox lastRow


Set cRng = sht.Range(Cells(1, startCol), Cells(lastRow, lastCol)).Select
cRng.Copy


Set pRng = sht.Cells(1, newStartCol).Select


pRng.PasteSpecial (xlPasteFormulas)
pRng.PasteSpecial (xlPasteFormats)


End Sub
 
Upvote 0
Code:
last_cell = Columns("A:A").Find("*", SearchDirection:=xlPrevious)
last_cell.Copy
Sheets("SOME_SHEET_NAME").Range("A1").PasteSpecial
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,114
Members
452,302
Latest member
TaMere

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