VBA code modification

ionelz

Active Member
Joined
Jan 14, 2018
Messages
254
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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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