Macro to pull file copy data form range

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone, Just need help with a macro. what I need is a macro to prompt agent to select .csv file then to copy data from range B2:H300 of the selected .csv and paste value to cell c5 of the excel. I was able to come up with file dialog is as far as i got.

VBA Code:
Sub PullCSVData()
   With application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .Filters.Add "Excel Files", "*.csv", 1
              .Show
               fullpath = .SelectedItems.item(1)
    End With
 End Sub

any help is greatly apprecated
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try this. Change "Result" to the name of the sheet in your book where you want to paste the data.

VBA Code:
Sub PullCSVData()
  Dim wb As Workbook, fullpath As String
  
  With Application.FileDialog(msoFileDialogFilePicker)
    .AllowMultiSelect = False
    .Filters.Add "Excel Files", "*.csv", 1
    If .Show <> -1 Then Exit Sub
    fullpath = .SelectedItems.Item(1)
    Set wb = Workbooks.Open(fullpath)
    wb.Sheets(1).Range("B2:H300").Copy ThisWorkbook.Sheets("Result").Range("C5")
    wb.Close False
  End With
End Sub
 
Upvote 0
Try this. Change "Result" to the name of the sheet in your book where you want to paste the data.

VBA Code:
Sub PullCSVData()
  Dim wb As Workbook, fullpath As String
 
  With Application.FileDialog(msoFileDialogFilePicker)
    .AllowMultiSelect = False
    .Filters.Add "Excel Files", "*.csv", 1
    If .Show <> -1 Then Exit Sub
    fullpath = .SelectedItems.Item(1)
    Set wb = Workbooks.Open(fullpath)
    wb.Sheets(1).Range("B2:H300").Copy ThisWorkbook.Sheets("Result").Range("C5")
    wb.Close False
  End With
End Sub
Thanks DanteAmor Works great much Appreciate it
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,693
Members
449,117
Latest member
Aaagu

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