Hi,
I have this simple VBA to Import one Excel file into another.
I would like to add a modification here :
FileSource.Worksheets("Sheet1").Range("b1 :b500").Copy
If M2="option 1" then
FileSource.Worksheets("Sheet1").Range("b1 :b500").Copy
If M2="option 2" then
FileSource.Worksheets("Sheet1").Range("a1 :a500").Copy
Private Sub CommandButton1_Click()
Dim FileFolder As FileDialog
Dim FileName As String
Dim FileSource As Workbook
Dim desWS As Worksheet
On Error GoTo myerror
Set desWS = ActiveSheet
Range("C4:B500").ClearContents
Set FileFolder = Application.FileDialog(msoFileDialogFilePicker)
FileFolder.Title = "Please Select a folder And file."
If FileFolder.Show = -1 Then
FileName = FileFoIder.SelectedItems(1)
Set FileSource = Workbooks.Open(FileName, 0, True)
FileSource.Worksheets("Sheet1").Range("bl :b500").Copy
desWS.Range("B4").PasteSpeciaI xlPasteVaIues
Else
'cancel pressed
End If
myerror:
Application.CutCopyMode = False
If Not FileSource Is Nothing Then FileSource.Close False
I have this simple VBA to Import one Excel file into another.
I would like to add a modification here :
FileSource.Worksheets("Sheet1").Range("b1 :b500").Copy
If M2="option 1" then
FileSource.Worksheets("Sheet1").Range("b1 :b500").Copy
If M2="option 2" then
FileSource.Worksheets("Sheet1").Range("a1 :a500").Copy
Private Sub CommandButton1_Click()
Dim FileFolder As FileDialog
Dim FileName As String
Dim FileSource As Workbook
Dim desWS As Worksheet
On Error GoTo myerror
Set desWS = ActiveSheet
Range("C4:B500").ClearContents
Set FileFolder = Application.FileDialog(msoFileDialogFilePicker)
FileFolder.Title = "Please Select a folder And file."
If FileFolder.Show = -1 Then
FileName = FileFoIder.SelectedItems(1)
Set FileSource = Workbooks.Open(FileName, 0, True)
FileSource.Worksheets("Sheet1").Range("bl :b500").Copy
desWS.Range("B4").PasteSpeciaI xlPasteVaIues
Else
'cancel pressed
End If
myerror:
Application.CutCopyMode = False
If Not FileSource Is Nothing Then FileSource.Close False