PC Review


Reply
Thread Tools Rate Thread

Can't select range

 
 
salgud
Guest
Posts: n/a
 
      25th Jul 2008
The following code works until the last line:

Option Explicit

Public Sub TribalInvCheck()
Dim wbTribalHist As Workbook
Dim wbTribalTR As Workbook
Dim wsTribalTR As Worksheet
Dim wsTribalHist As Worksheet
Dim rTRCell As Range
Dim lTRRow As Long
Dim lHistRow As Long
Dim rFoundID As Range
Dim sTRID As String
Dim rTribalHist As Range
Dim lHistCol As Long

Set wbTribalHist = ThisWorkbook
Set wbTribalTR = ActiveWorkbook
Set wsTribalTR = ActiveSheet
Set wsTribalHist = wbTribalHist.Worksheets("Historical")
'Range set temporarily until I can find out how to set the range to the
longest column in the range
Set rTribalHist = wsTribalHist.Range("A3:Iv150")

'Application.ScreenUpdating = False

If ThisWorkbook.Name = ActiveWorkbook.Name Then
MsgBox "Please do not run this macro from the workbook that contains it."
_
& Chr(10) & "Please select a Turnaround Report and then restart this
macro."
Exit Sub
End If

Set rTRCell = wsTribalTR.Range("A3")
sTRID = rTRCell.Value

Set rFoundID = rTribalHist.Find(sTRID, LookIn:=xlValues)
'wsTribalHist.Activate
'rFoundID.Select

lTRRow = 3
lHistRow = rFoundID.Row + 2
lHistCol = rFoundID.Column

wsTribalHist.Activate
wsTribalHist.Range(Cells(lHistRow, lHistCol)).Select <--- Method range of
object worksheet failed

End Sub

Any ideas why it doesn't recognize this range?
Thanks!
 
Reply With Quote
 
 
 
 
XP
Guest
Posts: n/a
 
      25th Jul 2008

I haven't tested it all the way through but I think you may need to change
this line:

wsTribalHist.Range(Cells(lHistRow, lHistCol)).Select

to this:

wsTribalHist.ActiveSheet.Cells(lHistRow, lHistCol).Select

Hope this helps.


"salgud" wrote:

> The following code works until the last line:
>
> Option Explicit
>
> Public Sub TribalInvCheck()
> Dim wbTribalHist As Workbook
> Dim wbTribalTR As Workbook
> Dim wsTribalTR As Worksheet
> Dim wsTribalHist As Worksheet
> Dim rTRCell As Range
> Dim lTRRow As Long
> Dim lHistRow As Long
> Dim rFoundID As Range
> Dim sTRID As String
> Dim rTribalHist As Range
> Dim lHistCol As Long
>
> Set wbTribalHist = ThisWorkbook
> Set wbTribalTR = ActiveWorkbook
> Set wsTribalTR = ActiveSheet
> Set wsTribalHist = wbTribalHist.Worksheets("Historical")
> 'Range set temporarily until I can find out how to set the range to the
> longest column in the range
> Set rTribalHist = wsTribalHist.Range("A3:Iv150")
>
> 'Application.ScreenUpdating = False
>
> If ThisWorkbook.Name = ActiveWorkbook.Name Then
> MsgBox "Please do not run this macro from the workbook that contains it."
> _
> & Chr(10) & "Please select a Turnaround Report and then restart this
> macro."
> Exit Sub
> End If
>
> Set rTRCell = wsTribalTR.Range("A3")
> sTRID = rTRCell.Value
>
> Set rFoundID = rTribalHist.Find(sTRID, LookIn:=xlValues)
> 'wsTribalHist.Activate
> 'rFoundID.Select
>
> lTRRow = 3
> lHistRow = rFoundID.Row + 2
> lHistCol = rFoundID.Column
>
> wsTribalHist.Activate
> wsTribalHist.Range(Cells(lHistRow, lHistCol)).Select <--- Method range of
> object worksheet failed
>
> End Sub
>
> Any ideas why it doesn't recognize this range?
> Thanks!
>

 
Reply With Quote
 
james.billy@gmail.com
Guest
Posts: n/a
 
      25th Jul 2008
On Jul 26, 12:05*am, salgud <spamboy6...@comcast.net> wrote:
> The following code works until the last line:
>
> Option Explicit
>
> Public Sub TribalInvCheck()
> Dim wbTribalHist As Workbook
> Dim wbTribalTR As Workbook
> Dim wsTribalTR As Worksheet
> Dim wsTribalHist As Worksheet
> Dim rTRCell As Range
> Dim lTRRow As Long
> Dim lHistRow As Long
> Dim rFoundID As Range
> Dim sTRID As String
> Dim rTribalHist As Range
> Dim lHistCol As Long
>
> Set wbTribalHist = ThisWorkbook
> Set wbTribalTR = ActiveWorkbook
> Set wsTribalTR = ActiveSheet
> Set wsTribalHist = wbTribalHist.Worksheets("Historical")
> 'Range set temporarily until I can find out how to set the range to the
> longest column in the range
> Set rTribalHist = wsTribalHist.Range("A3:Iv150")
>
> 'Application.ScreenUpdating = False
>
> If ThisWorkbook.Name = ActiveWorkbook.Name Then
> * MsgBox "Please do not run this macro from the workbook that contains it."
> _
> * * & Chr(10) & "Please select a Turnaround Report and then restart this
> macro."
> * Exit Sub
> End If
>
> Set rTRCell = wsTribalTR.Range("A3")
> sTRID = rTRCell.Value
>
> Set rFoundID = rTribalHist.Find(sTRID, LookIn:=xlValues)
> 'wsTribalHist.Activate
> 'rFoundID.Select
>
> lTRRow = 3
> lHistRow = rFoundID.Row + 2
> lHistCol = rFoundID.Column
>
> wsTribalHist.Activate
> wsTribalHist.Range(Cells(lHistRow, lHistCol)).Select <--- Method range of
> object worksheet failed
>
> End Sub
>
> Any ideas why it doesn't recognize this range?
> Thanks!


When you stop the code (i.e. put a breakpoint in) what are the
variables lHistRow and lHistCol, to me the only thing that would make
any sense is if it wasn't finding sTRID. Either that or the active
workbook wasn't wbTribalHist, aslong as the activeworkbook is
wbTribalHist (so try changing the wsTribalHist to wbTribalHist) the
range should then select (I think).

James
 
Reply With Quote
 
james.billy@gmail.com
Guest
Posts: n/a
 
      25th Jul 2008
On Jul 26, 12:23*am, XP <X...@discussions.microsoft.com> wrote:
> I haven't tested it all the way through but I think you may need to change
> this line:
>
> wsTribalHist.Range(Cells(lHistRow, lHistCol)).Select
>
> to this:
>
> wsTribalHist.ActiveSheet.Cells(lHistRow, lHistCol).Select
>
> Hope this helps.
>
> "salgud" wrote:
> > The following code works until the last line:

>
> > Option Explicit

>
> > Public Sub TribalInvCheck()
> > Dim wbTribalHist As Workbook
> > Dim wbTribalTR As Workbook
> > Dim wsTribalTR As Worksheet
> > Dim wsTribalHist As Worksheet
> > Dim rTRCell As Range
> > Dim lTRRow As Long
> > Dim lHistRow As Long
> > Dim rFoundID As Range
> > Dim sTRID As String
> > Dim rTribalHist As Range
> > Dim lHistCol As Long

>
> > Set wbTribalHist = ThisWorkbook
> > Set wbTribalTR = ActiveWorkbook
> > Set wsTribalTR = ActiveSheet
> > Set wsTribalHist = wbTribalHist.Worksheets("Historical")
> > 'Range set temporarily until I can find out how to set the range to the
> > longest column in the range
> > Set rTribalHist = wsTribalHist.Range("A3:Iv150")

>
> > 'Application.ScreenUpdating = False

>
> > If ThisWorkbook.Name = ActiveWorkbook.Name Then
> > * MsgBox "Please do not run this macro from the workbook that contains it."
> > _
> > * * & Chr(10) & "Please select a Turnaround Report and then restartthis
> > macro."
> > * Exit Sub
> > End If

>
> > Set rTRCell = wsTribalTR.Range("A3")
> > sTRID = rTRCell.Value

>
> > Set rFoundID = rTribalHist.Find(sTRID, LookIn:=xlValues)
> > 'wsTribalHist.Activate
> > 'rFoundID.Select

>
> > lTRRow = 3
> > lHistRow = rFoundID.Row + 2
> > lHistCol = rFoundID.Column

>
> > wsTribalHist.Activate
> > wsTribalHist.Range(Cells(lHistRow, lHistCol)).Select <--- Method range of
> > object worksheet failed

>
> > End Sub

>
> > Any ideas why it doesn't recognize this range?
> > Thanks!


wsTribalHist is a worksheet object therefore there is no point adding
the activesheet as it will error just the same, I believe the problem
is caused because the workbook is not active and thats what needs to
be activated before the range is selected.

James
 
Reply With Quote
 
salgud
Guest
Posts: n/a
 
      25th Jul 2008
On Fri, 25 Jul 2008 10:23:00 -0700, XP wrote:

> I haven't tested it all the way through but I think you may need to change
> this line:
>
> wsTribalHist.Range(Cells(lHistRow, lHistCol)).Select
>
> to this:
>
> wsTribalHist.ActiveSheet.Cells(lHistRow, lHistCol).Select
>
> Hope this helps.
>
>
> "salgud" wrote:
>
>> The following code works until the last line:
>>
>> Option Explicit
>>
>> Public Sub TribalInvCheck()
>> Dim wbTribalHist As Workbook
>> Dim wbTribalTR As Workbook
>> Dim wsTribalTR As Worksheet
>> Dim wsTribalHist As Worksheet
>> Dim rTRCell As Range
>> Dim lTRRow As Long
>> Dim lHistRow As Long
>> Dim rFoundID As Range
>> Dim sTRID As String
>> Dim rTribalHist As Range
>> Dim lHistCol As Long
>>
>> Set wbTribalHist = ThisWorkbook
>> Set wbTribalTR = ActiveWorkbook
>> Set wsTribalTR = ActiveSheet
>> Set wsTribalHist = wbTribalHist.Worksheets("Historical")
>> 'Range set temporarily until I can find out how to set the range to the
>> longest column in the range
>> Set rTribalHist = wsTribalHist.Range("A3:Iv150")
>>
>> 'Application.ScreenUpdating = False
>>
>> If ThisWorkbook.Name = ActiveWorkbook.Name Then
>> MsgBox "Please do not run this macro from the workbook that contains it."
>> _
>> & Chr(10) & "Please select a Turnaround Report and then restart this
>> macro."
>> Exit Sub
>> End If
>>
>> Set rTRCell = wsTribalTR.Range("A3")
>> sTRID = rTRCell.Value
>>
>> Set rFoundID = rTribalHist.Find(sTRID, LookIn:=xlValues)
>> 'wsTribalHist.Activate
>> 'rFoundID.Select
>>
>> lTRRow = 3
>> lHistRow = rFoundID.Row + 2
>> lHistCol = rFoundID.Column
>>
>> wsTribalHist.Activate
>> wsTribalHist.Range(Cells(lHistRow, lHistCol)).Select <--- Method range of
>> object worksheet failed
>>
>> End Sub
>>
>> Any ideas why it doesn't recognize this range?
>> Thanks!
>>


Thanks, that did it. Forgot to try a "." instead of a "(". Sometimes that's
the trick!
 
Reply With Quote
 
salgud
Guest
Posts: n/a
 
      25th Jul 2008
On Fri, 25 Jul 2008 10:24:13 -0700 (PDT), (E-Mail Removed) wrote:

> On Jul 26, 12:05*am, salgud <spamboy6...@comcast.net> wrote:
>> The following code works until the last line:
>>
>> Option Explicit
>>
>> Public Sub TribalInvCheck()
>> Dim wbTribalHist As Workbook
>> Dim wbTribalTR As Workbook
>> Dim wsTribalTR As Worksheet
>> Dim wsTribalHist As Worksheet
>> Dim rTRCell As Range
>> Dim lTRRow As Long
>> Dim lHistRow As Long
>> Dim rFoundID As Range
>> Dim sTRID As String
>> Dim rTribalHist As Range
>> Dim lHistCol As Long
>>
>> Set wbTribalHist = ThisWorkbook
>> Set wbTribalTR = ActiveWorkbook
>> Set wsTribalTR = ActiveSheet
>> Set wsTribalHist = wbTribalHist.Worksheets("Historical")
>> 'Range set temporarily until I can find out how to set the range to the
>> longest column in the range
>> Set rTribalHist = wsTribalHist.Range("A3:Iv150")
>>
>> 'Application.ScreenUpdating = False
>>
>> If ThisWorkbook.Name = ActiveWorkbook.Name Then
>> * MsgBox "Please do not run this macro from the workbook that contains it."
>> _
>> * * & Chr(10) & "Please select a Turnaround Report and then restart this
>> macro."
>> * Exit Sub
>> End If
>>
>> Set rTRCell = wsTribalTR.Range("A3")
>> sTRID = rTRCell.Value
>>
>> Set rFoundID = rTribalHist.Find(sTRID, LookIn:=xlValues)
>> 'wsTribalHist.Activate
>> 'rFoundID.Select
>>
>> lTRRow = 3
>> lHistRow = rFoundID.Row + 2
>> lHistCol = rFoundID.Column
>>
>> wsTribalHist.Activate
>> wsTribalHist.Range(Cells(lHistRow, lHistCol)).Select <--- Method range of
>> object worksheet failed
>>
>> End Sub
>>
>> Any ideas why it doesn't recognize this range?
>> Thanks!

>
> When you stop the code (i.e. put a breakpoint in) what are the
> variables lHistRow and lHistCol, to me the only thing that would make
> any sense is if it wasn't finding sTRID. Either that or the active
> workbook wasn't wbTribalHist, aslong as the activeworkbook is
> wbTribalHist (so try changing the wsTribalHist to wbTribalHist) the
> range should then select (I think).
>
> James


Thanks for your reply. See XP's reply above, that was it.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
use ComboBox value to select range and then use selected range tocreate a chart Jerry Microsoft Excel Programming 3 22nd Jun 2011 02:15 PM
How can change range to select active rows instead of :=Range("S10 ldiaz Microsoft Excel Misc 7 29th Aug 2008 03:52 PM
macro to select range from active cell range name string aelbob Microsoft Excel Programming 2 14th Jul 2008 09:19 PM
When entering data into a range of cells, select the entire range. =?Utf-8?B?UQ==?= Microsoft Excel Misc 0 26th Sep 2007 04:36 AM
Compare a selected Range with a Named range and select cells that do not exist PCLIVE Microsoft Excel Programming 1 18th Oct 2005 07:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:47 AM.