Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Selecting a Range using Inputbox Method

The following procedure works perfectly when the commented line is used
but when I try to use the Inputbox I get an error: "Ojbect required."
It turns out that the list may not start at the same place everytime
and there may be blanks or gaps. I tried to learn about the Inputbox
Method from the sample code at the bottom, which is from a book, but I
can't get it to work either. Any help would be appreciated.

Public Sub RunReports()
Dim vManagers As Range, vManager As Range, DataArray(5)
Windows("DataTable.xls").Activate
'Set vManagers = Range(Cells(23, "D"), Cells(Rows.Count,
"D").End(xlUp))
Set vManagers = Application.InputBox("Use the mouse to select all
manager names in Column D", "Select Range", , , , , , 8)
On Error Resume Next
For Each vManager In vManagers
If vManager.Value = "S. O' Neil" Then
vManager.Activate
DataArray(1) = ActiveCell.Offset(0, -3)
DataArray(2) = ActiveCell.Offset(0, -1)
DataArray(3) = ActiveCell.Offset(0, 1)
DataArray(4) = ActiveCell.Offset(0, 3)
DataArray(5) = ActiveCell.Offset(0, 7)
Windows("Check Deposit Report.xls").Activate
Sheets("CHECK-DEPOSIT").Copy After:=Sheets(1)
ActiveSheet.Unprotect
Range("F43").Value = DataArray(1)
Range("B43").Value = DataArray(2)
Range("F32").Value = DataArray(3)
Range("A43").Value = DataArray(4)
Range("I27").Value = -DataArray(5)
Windows("DataTable.xls").Activate
End If
Next
Windows("Check Deposit Report.xls").Activate
End Sub

Sub GetRange()
Dim UserRange As Range
Default = Selection.Address 'Assignment to constant not permitted.
On Error GoTo Canceled
Set UserRange = Application.InputBox(prompt:="Range to erase:",
Title:="Range Erase", Default:=Default, Type:=8)
UserRange.Clear
UserRange.Select
Canceled:
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Selecting a Range using Inputbox Method

Is that if you Cancel?

If so try

On Error Resume Next
Set vManagers = Application.InputBox("Use the mouse to select all
manager names in Column D", "Select Range", , , , , , 8)
On Error GoTo 0
If Not vManagers Is Nothing Then
For Each vManager In vManagers


--
HTH

Bob Phillips

"John Pierce" wrote in message
ups.com...
The following procedure works perfectly when the commented line is used
but when I try to use the Inputbox I get an error: "Ojbect required."
It turns out that the list may not start at the same place everytime
and there may be blanks or gaps. I tried to learn about the Inputbox
Method from the sample code at the bottom, which is from a book, but I
can't get it to work either. Any help would be appreciated.

Public Sub RunReports()
Dim vManagers As Range, vManager As Range, DataArray(5)
Windows("DataTable.xls").Activate
'Set vManagers = Range(Cells(23, "D"), Cells(Rows.Count,
"D").End(xlUp))
Set vManagers = Application.InputBox("Use the mouse to select all
manager names in Column D", "Select Range", , , , , , 8)
On Error Resume Next
For Each vManager In vManagers
If vManager.Value = "S. O' Neil" Then
vManager.Activate
DataArray(1) = ActiveCell.Offset(0, -3)
DataArray(2) = ActiveCell.Offset(0, -1)
DataArray(3) = ActiveCell.Offset(0, 1)
DataArray(4) = ActiveCell.Offset(0, 3)
DataArray(5) = ActiveCell.Offset(0, 7)
Windows("Check Deposit Report.xls").Activate
Sheets("CHECK-DEPOSIT").Copy After:=Sheets(1)
ActiveSheet.Unprotect
Range("F43").Value = DataArray(1)
Range("B43").Value = DataArray(2)
Range("F32").Value = DataArray(3)
Range("A43").Value = DataArray(4)
Range("I27").Value = -DataArray(5)
Windows("DataTable.xls").Activate
End If
Next
Windows("Check Deposit Report.xls").Activate
End Sub

Sub GetRange()
Dim UserRange As Range
Default = Selection.Address 'Assignment to constant not permitted.
On Error GoTo Canceled
Set UserRange = Application.InputBox(prompt:="Range to erase:",
Title:="Range Erase", Default:=Default, Type:=8)
UserRange.Clear
UserRange.Select
Canceled:
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Selecting a Range using Inputbox Method

Bob,
Thanks for the help. The problem wasn't on cancel but I put you code in
my procedure anyway and it works. The difference seems to be the Error
handling, something I'm not very good at. I saw some code recently where
at the end the variables were set to Nothing. When I test this thing
over and over it seems that it gets confused somewhat. Should I clear my
variables and array, and if so how?

*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Selecting a Range using Inputbox Method

John,

there are differing views on this. I personally don't bother unless I have a
big app and they become redundant early, then I do it to conserve memory. I
am firmly of the belief that they clear at the end themselves, and I have
had discussions with people on these boards about it (you can read one here
http://tinyurl.com/azq7r if you are interested). People who maintain you
should will clear object variables, but you don't see them clearing string
variables, or even arrays!

But, conversely, it never hurts to unset them.

--
HTH

Bob Phillips

"John Pierce" wrote in message
...
Bob,
Thanks for the help. The problem wasn't on cancel but I put you code in
my procedure anyway and it works. The difference seems to be the Error
handling, something I'm not very good at. I saw some code recently where
at the end the variables were set to Nothing. When I test this thing
over and over it seems that it gets confused somewhat. Should I clear my
variables and array, and if so how?

*** Sent via Developersdex http://www.developersdex.com ***



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting Cancel in an InputBox Method Connie Excel Discussion (Misc queries) 2 October 19th 06 01:32 PM
Error 424 with inputbox method after OK Herman[_4_] Excel Programming 1 September 14th 04 11:12 PM
Cancel button in Inputbox method MiRa Excel Programming 2 November 14th 03 01:04 PM
Using Arrays in InputBox Method verizon Excel Programming 4 July 20th 03 08:14 AM
Inputbox method using type:=8 - How to Cancel? Jim Cone Excel Programming 0 July 8th 03 06:15 PM


All times are GMT +1. The time now is 09:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"