Mountainman141
New Member
- Joined
- Aug 14, 2008
- Messages
- 3
Still kinda new at this.
I am trying to write a sub that will allow the user to select a range and a collection of files. That range will be pulled from each of the files selected and then pasted to a new workbook (same sheet). I will also be doing the same thing but instead to one sheet give each file its own sheet. I have a problem with the range. When I grab the range from the user, I can immediately select that range in the open worksheet. However, when I move over to the next workbook, it seems as if its out of scope or something. The error says object required. I have stripped the code down as much as I can to the part that is causing the problem.
Public userRange As Range
Sub test1()
fn = GetUserFiles()
Workbooks.Open fn(1)
Set temp = ActiveWorkbook
Set userRange = GetUserRange()
userRange.Select
temp.Close
Workbooks.Open "C:\test.xls"
Worksheets("Sheet1").Select
userRange.Select
End Sub
Function GetUserFiles()
fn = Application.GetOpenFilename("Excell Worksheets (*xls.),*.xls", , "Source Files", , True)
If TypeName(fn) = "Boolean" Then Exit Function
GetUserFiles = fn
End Function
Function GetUserRange() As Range
Application.ScreenUpdating = True
Dim oRangeSelected As Range
On Error Resume Next
Set oRangeSelected = Application.InputBox("Please select a range of cells!", _
"Select A Range", Selection.Address, , , , , 8)
If oRangeSelected Is Nothing Then
MsgBox "Action canceled!"
Exit Function
Else
Set GetUserRange = oRangeSelected
End If
Application.ScreenUpdating = False
End Function
I am trying to write a sub that will allow the user to select a range and a collection of files. That range will be pulled from each of the files selected and then pasted to a new workbook (same sheet). I will also be doing the same thing but instead to one sheet give each file its own sheet. I have a problem with the range. When I grab the range from the user, I can immediately select that range in the open worksheet. However, when I move over to the next workbook, it seems as if its out of scope or something. The error says object required. I have stripped the code down as much as I can to the part that is causing the problem.
Public userRange As Range
Sub test1()
fn = GetUserFiles()
Workbooks.Open fn(1)
Set temp = ActiveWorkbook
Set userRange = GetUserRange()
userRange.Select
temp.Close
Workbooks.Open "C:\test.xls"
Worksheets("Sheet1").Select
userRange.Select
End Sub
Function GetUserFiles()
fn = Application.GetOpenFilename("Excell Worksheets (*xls.),*.xls", , "Source Files", , True)
If TypeName(fn) = "Boolean" Then Exit Function
GetUserFiles = fn
End Function
Function GetUserRange() As Range
Application.ScreenUpdating = True
Dim oRangeSelected As Range
On Error Resume Next
Set oRangeSelected = Application.InputBox("Please select a range of cells!", _
"Select A Range", Selection.Address, , , , , 8)
If oRangeSelected Is Nothing Then
MsgBox "Action canceled!"
Exit Function
Else
Set GetUserRange = oRangeSelected
End If
Application.ScreenUpdating = False
End Function