VBA code modification

ionelz

Board Regular
Joined
Jan 14, 2018
Messages
248
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have this code for Copy and Paste. I want a modification on bolded line
I want to COUNT last row with data in FileSource (from where I Copy) and replace 100000 with that number
I want to count in Column A, not in entire sheet


Dim FileFolder As FileDialog
Dim FileName As String
Dim FileChosen As Integer
Dim FileSource As Workbook
Dim FileDestination As Worksheet

Set FileDestination = ActiveSheet

Range("B4:F100000").ClearContents
Range("B2:F2").ClearContents

Set FileFolder = Application.FileDialog(msoFileDialogFilePicker)
Application.DisplayAlerts = False
FileFolder.Title = "Please Select a Folder and File"
FileChosen = FileFolder.Show
FileName = FileFolder.SelectedItems(1)
Set FileSource = Workbooks.Open(FileName)

Sheets("Sheet1").Range("A2:E100000").Copy

FileDestination.Range("B4").PasteSpecial xlPasteValues
FileDestination.Range("B2").Value = FileName

FileSource.Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Replace:
Sheets("Sheet1").Range("A2:E100000").Copy

with
lastRow = Range("A100000").End(xlUp).Row
Sheets("Sheet1").Range("A2:E" & lastRow).Copy

Bafta.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,419
Messages
6,124,796
Members
449,189
Latest member
kristinh

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