I know that this should be rather simple but i seem to be missing a step to get it to work. and have been unable to find a solution on the net.
The aim is that I click on the open button to find and open an unknown workbook that contains the data that I need to imput into my current workbook, once the unknown workbook is opened it should automatically select my range (number of columns known, but number of rows unknown- the number of rows needed to be copied will change each time the unknown workbook is opened). this range will then be copied and pasted into the original workbook (book1.xls) starting in cellA17.
the below code opens the unknown workbook fine but it will not select the range properly. I have tried the range select in the unknown workbook by itself and it works like a charm but in the below code it seems to get very very confused as to which workbook it should be looking in and i don’t know how to make it point correctly so that it will work.
my code:
Sub cmdopen_Click()
'find and open file
Dim vaFiles As Variant
Dim i As Long
vaFiles = Application.Get OpenFilename _
(FileFilter:="E xcel Filer (*.xls),*.xls", _
Title:="Open File(s)", MultiSelect:=Tr ue)
If Not IsArray(vaFiles ) Then Exit Sub
With Application
.ScreenUpdating = False
For i = 1 To UBound(vaFiles)
Workbooks.Open vaFiles(i)
Next i
.ScreenUpdating = True
End With
'so far code works great but from here i start having problems.....
' select woksheet2 and select range of cells from A2 (to E2 and down unknow number of rows)
Worksheets("She et2").Range("a2 ").Select
Range(ActiveCel l, Range(ActiveCel l.Address).End _
(xlToRight).End (xlDown)).Selec t.Copy
' this seems to work perfect if i run these three lines in the new workbook, but when running it in conjunction with the code above it it seems to select the data in cell A2 from the original workbook and paste it in the active cell in the newly opened workbook, the active cell is not A2 in new workbook
I would then like the copied data pasted back into original workbook ("book1.xls) in cell A17
any help would be greatly appreciated.
The aim is that I click on the open button to find and open an unknown workbook that contains the data that I need to imput into my current workbook, once the unknown workbook is opened it should automatically select my range (number of columns known, but number of rows unknown- the number of rows needed to be copied will change each time the unknown workbook is opened). this range will then be copied and pasted into the original workbook (book1.xls) starting in cellA17.
the below code opens the unknown workbook fine but it will not select the range properly. I have tried the range select in the unknown workbook by itself and it works like a charm but in the below code it seems to get very very confused as to which workbook it should be looking in and i don’t know how to make it point correctly so that it will work.
my code:
Sub cmdopen_Click()
'find and open file
Dim vaFiles As Variant
Dim i As Long
vaFiles = Application.Get OpenFilename _
(FileFilter:="E xcel Filer (*.xls),*.xls", _
Title:="Open File(s)", MultiSelect:=Tr ue)
If Not IsArray(vaFiles ) Then Exit Sub
With Application
.ScreenUpdating = False
For i = 1 To UBound(vaFiles)
Workbooks.Open vaFiles(i)
Next i
.ScreenUpdating = True
End With
'so far code works great but from here i start having problems.....
' select woksheet2 and select range of cells from A2 (to E2 and down unknow number of rows)
Worksheets("She et2").Range("a2 ").Select
Range(ActiveCel l, Range(ActiveCel l.Address).End _
(xlToRight).End (xlDown)).Selec t.Copy
' this seems to work perfect if i run these three lines in the new workbook, but when running it in conjunction with the code above it it seems to select the data in cell A2 from the original workbook and paste it in the active cell in the newly opened workbook, the active cell is not A2 in new workbook
I would then like the copied data pasted back into original workbook ("book1.xls) in cell A17
any help would be greatly appreciated.
Comment