Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

How can I copy specific range values in Excel VBA?

$
0
0

How can I copy specific range values in Excel VBA? I'm trying to copy a range by first creating an inputbox for the user to enter the range in another workbook, then copy that range's values from all the selected workbooks into one workbook.

This is what I have, but it copies only one set of values.

    FileNames = Application.GetOpenFilename(FileFilter:="Excel Filter (*.csv), *.csv", Title:="Open File(s)", MultiSelect:=True)
    nw = UBound(FileNames)
    Workbooks.Open FileNames(1)
    Set UserRange = Application.InputBox(Title:="Select Range", Prompt:="Range", Default:=DefaultRange, Type:=8)
    For i = 1 To nw
Set FileNames(i) = ActiveWorkbook
        UserRange.Copy
        tWB.Worksheets("Data").range("A"& i).PasteSpecial Transpose:=True
    Next i

Edit: I need to only open one workbook, define UserRange as the range, and copy the values in that range in all selected workbooks, then paste them into the tWB workbook.


Viewing all articles
Browse latest Browse all 88854

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>