PC Review


Reply
Thread Tools Rate Thread

Can't get this to work

 
 
ranswrt
Guest
Posts: n/a
 
      8th Aug 2008
The following code worked until I changed how I started it. It originally
started with button on a worksheet (not a control button). I changed it to a
control button now it doesn't work. Everything else in the procedure works
fine. The code is:

Set ycell = Sheets("Estimates DB").Range("estdbno")
Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"

The error I get is:

Method 'Range" of object '_Worksheet' failed.

Everything is set right. ycell as range, the sheet name and cell name are
correct. I was wondering if it could be because I changed it to a control
button and moved the procedure from a module to to an excel object. Any help
on this would be greatly appreciated.
Thanks
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      8th Aug 2008
What does "It don't work" mean? It won't start when the button is clicked?
It gives an error message? What specifically don't work?

"ranswrt" wrote:

> The following code worked until I changed how I started it. It originally
> started with button on a worksheet (not a control button). I changed it to a
> control button now it doesn't work. Everything else in the procedure works
> fine. The code is:
>
> Set ycell = Sheets("Estimates DB").Range("estdbno")
> Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
>
> The error I get is:
>
> Method 'Range" of object '_Worksheet' failed.
>
> Everything is set right. ycell as range, the sheet name and cell name are
> correct. I was wondering if it could be because I changed it to a control
> button and moved the procedure from a module to to an excel object. Any help
> on this would be greatly appreciated.
> Thanks

 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      8th Aug 2008
Your issue revolves around the sheet reference. Ycell is on sheet Estimates
DB but when you use Range at the beginning of
Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"

if is the same as
Activesheet.Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name =
"estdbnorng"

which is probably not correct as Estimates DB is probably not the active
sheet. Try this...

with Sheets("Estimates DB")
Set ycell = .Range("estdbno")
..Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
end with

--
HTH...

Jim Thomlinson


"ranswrt" wrote:

> The following code worked until I changed how I started it. It originally
> started with button on a worksheet (not a control button). I changed it to a
> control button now it doesn't work. Everything else in the procedure works
> fine. The code is:
>
> Set ycell = Sheets("Estimates DB").Range("estdbno")
> Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
>
> The error I get is:
>
> Method 'Range" of object '_Worksheet' failed.
>
> Everything is set right. ycell as range, the sheet name and cell name are
> correct. I was wondering if it could be because I changed it to a control
> button and moved the procedure from a module to to an excel object. Any help
> on this would be greatly appreciated.
> Thanks

 
Reply With Quote
 
ranswrt
Guest
Posts: n/a
 
      8th Aug 2008
The procedure work when the button is clicked until it gets to this line and
I get the error message.

Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"

"JLGWhiz" wrote:

> What does "It don't work" mean? It won't start when the button is clicked?
> It gives an error message? What specifically don't work?
>
> "ranswrt" wrote:
>
> > The following code worked until I changed how I started it. It originally
> > started with button on a worksheet (not a control button). I changed it to a
> > control button now it doesn't work. Everything else in the procedure works
> > fine. The code is:
> >
> > Set ycell = Sheets("Estimates DB").Range("estdbno")
> > Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
> >
> > The error I get is:
> >
> > Method 'Range" of object '_Worksheet' failed.
> >
> > Everything is set right. ycell as range, the sheet name and cell name are
> > correct. I was wondering if it could be because I changed it to a control
> > button and moved the procedure from a module to to an excel object. Any help
> > on this would be greatly appreciated.
> > Thanks

 
Reply With Quote
 
Ak Man
Guest
Posts: n/a
 
      8th Aug 2008
Probably u can do is:
Sheets("Estimates DB").Select
Set ycell = Range("estdbno")
Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"

coz once i had a similar problem with using sheet("sheetname").range

--
Ak


"Jim Thomlinson" wrote:

> Your issue revolves around the sheet reference. Ycell is on sheet Estimates
> DB but when you use Range at the beginning of
> Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
>
> if is the same as
> Activesheet.Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name =
> "estdbnorng"
>
> which is probably not correct as Estimates DB is probably not the active
> sheet. Try this...
>
> with Sheets("Estimates DB")
> Set ycell = .Range("estdbno")
> .Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
> end with
>
> --
> HTH...
>
> Jim Thomlinson
>
>
> "ranswrt" wrote:
>
> > The following code worked until I changed how I started it. It originally
> > started with button on a worksheet (not a control button). I changed it to a
> > control button now it doesn't work. Everything else in the procedure works
> > fine. The code is:
> >
> > Set ycell = Sheets("Estimates DB").Range("estdbno")
> > Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
> >
> > The error I get is:
> >
> > Method 'Range" of object '_Worksheet' failed.
> >
> > Everything is set right. ycell as range, the sheet name and cell name are
> > correct. I was wondering if it could be because I changed it to a control
> > button and moved the procedure from a module to to an excel object. Any help
> > on this would be greatly appreciated.
> > Thanks

 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      8th Aug 2008
While that will probably work it is a very bad practice to select sheets or
ranges. It makes the code slower to execute. It bloats the code and it makes
it much more suseptible to failure in the future as you modify code and
potentially change the active sheet around. Just my 2 cents...
--
HTH...

Jim Thomlinson


"Ak Man" wrote:

> Probably u can do is:
> Sheets("Estimates DB").Select
> Set ycell = Range("estdbno")
> Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
>
> coz once i had a similar problem with using sheet("sheetname").range
>
> --
> Ak
>
>
> "Jim Thomlinson" wrote:
>
> > Your issue revolves around the sheet reference. Ycell is on sheet Estimates
> > DB but when you use Range at the beginning of
> > Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
> >
> > if is the same as
> > Activesheet.Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name =
> > "estdbnorng"
> >
> > which is probably not correct as Estimates DB is probably not the active
> > sheet. Try this...
> >
> > with Sheets("Estimates DB")
> > Set ycell = .Range("estdbno")
> > .Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
> > end with
> >
> > --
> > HTH...
> >
> > Jim Thomlinson
> >
> >
> > "ranswrt" wrote:
> >
> > > The following code worked until I changed how I started it. It originally
> > > started with button on a worksheet (not a control button). I changed it to a
> > > control button now it doesn't work. Everything else in the procedure works
> > > fine. The code is:
> > >
> > > Set ycell = Sheets("Estimates DB").Range("estdbno")
> > > Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
> > >
> > > The error I get is:
> > >
> > > Method 'Range" of object '_Worksheet' failed.
> > >
> > > Everything is set right. ycell as range, the sheet name and cell name are
> > > correct. I was wondering if it could be because I changed it to a control
> > > button and moved the procedure from a module to to an excel object. Any help
> > > on this would be greatly appreciated.
> > > Thanks

 
Reply With Quote
 
ranswrt
Guest
Posts: n/a
 
      8th Aug 2008
Thanks that worked great. I new there would be an easy answer.

"Jim Thomlinson" wrote:

> Your issue revolves around the sheet reference. Ycell is on sheet Estimates
> DB but when you use Range at the beginning of
> Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
>
> if is the same as
> Activesheet.Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name =
> "estdbnorng"
>
> which is probably not correct as Estimates DB is probably not the active
> sheet. Try this...
>
> with Sheets("Estimates DB")
> Set ycell = .Range("estdbno")
> .Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
> end with
>
> --
> HTH...
>
> Jim Thomlinson
>
>
> "ranswrt" wrote:
>
> > The following code worked until I changed how I started it. It originally
> > started with button on a worksheet (not a control button). I changed it to a
> > control button now it doesn't work. Everything else in the procedure works
> > fine. The code is:
> >
> > Set ycell = Sheets("Estimates DB").Range("estdbno")
> > Range(ycell.Offset(1, 0), ycell.Offset(estnum, 0)).Name = "estdbnorng"
> >
> > The error I get is:
> >
> > Method 'Range" of object '_Worksheet' failed.
> >
> > Everything is set right. ycell as range, the sheet name and cell name are
> > correct. I was wondering if it could be because I changed it to a control
> > button and moved the procedure from a module to to an excel object. Any help
> > on this would be greatly appreciated.
> > Thanks

 
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
HOW TO MAKE A LIST OF WORK SHEET IN WORK BOOK IN EXCEL 2007 goutam Microsoft Excel Programming 1 1st Feb 2008 07:40 AM
If I have a work sheet protected and try to run a macro to hide rows or columns it won't work. Correct? Marc Microsoft Excel Programming 2 12th Jul 2006 04:10 AM
Working without word work file, memory nearly full. Save work. =?Utf-8?B?RGF2ZSBXaGl0?= Microsoft Word Document Management 1 17th Nov 2004 09:39 PM
Wireless mouse/keyboard don't work after system restart only work after power down tfdempsey@comcast.net Windows XP General 1 1st Apr 2004 04:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:19 PM.