PC Review


Reply
Thread Tools Rate Thread

cell value from different worksheet

 
 
JPCPA
Guest
Posts: n/a
 
      30th Jan 2008
I have a user form that, based on the option button selected, a value needs
to be returned from a different cell in a separate worksheet. I get an out
of range error when I try the following code:

Sheets("Sample Selection").Select
ActiveSheet.Unprotect
Cells(2, 5) = Worksheets("SampleCalc").Cells(3, 45)

What am I doing wrong?

--
JP
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      30th Jan 2008
subscript out of range errors means that the thing that caused the error doesn't
exist in the collection you're using.

Maybe it's a typo in the worksheet name (which line caused the error)?

or maybe the activeworkbook wasn't what you thought it was and so the worksheet
didn't exist in the real workbook that was active.

with activeworkbook.worksheets("sample selection")
.unprotect
.cells(2,5).value _
= activeworkbook.worksheets("samplecalc").cells(3,45).value
end with



JPCPA wrote:
>
> I have a user form that, based on the option button selected, a value needs
> to be returned from a different cell in a separate worksheet. I get an out
> of range error when I try the following code:
>
> Sheets("Sample Selection").Select
> ActiveSheet.Unprotect
> Cells(2, 5) = Worksheets("SampleCalc").Cells(3, 45)
>
> What am I doing wrong?
>
> --
> JP


--

Dave Peterson
 
Reply With Quote
 
Nigel
Guest
Posts: n/a
 
      30th Jan 2008
Your code should work but no need to select

With Sheets("Sample Selection")
.Unprotect
.Cells(2,5) = Sheets("SampleCalc").Cells(3,45)
End With


--

Regards,
Nigel
(E-Mail Removed)



"JPCPA" <(E-Mail Removed)> wrote in message
news:3E2C7B3E-0EA5-4ADC-ACA9-(E-Mail Removed)...
>I have a user form that, based on the option button selected, a value needs
> to be returned from a different cell in a separate worksheet. I get an
> out
> of range error when I try the following code:
>
> Sheets("Sample Selection").Select
> ActiveSheet.Unprotect
> Cells(2, 5) = Worksheets("SampleCalc").Cells(3, 45)
>
> What am I doing wrong?
>
> --
> JP


 
Reply With Quote
 
JPCPA
Guest
Posts: n/a
 
      30th Jan 2008
Dave & Nigel,
Thanks for the responses -

Dave, I had the sheet spelled wrong (missing space). I also was referencing
the wrong cell - I did column,row, rather than row, column, hence the value
of the referenced cell was blank.

Nigel, Excellent thing to know. I've always selected the sheet first.
I'll note this for the future. Thank you.
--
JP


"Nigel" wrote:

> Your code should work but no need to select
>
> With Sheets("Sample Selection")
> .Unprotect
> .Cells(2,5) = Sheets("SampleCalc").Cells(3,45)
> End With
>
>
> --
>
> Regards,
> Nigel
> (E-Mail Removed)
>
>
>
> "JPCPA" <(E-Mail Removed)> wrote in message
> news:3E2C7B3E-0EA5-4ADC-ACA9-(E-Mail Removed)...
> >I have a user form that, based on the option button selected, a value needs
> > to be returned from a different cell in a separate worksheet. I get an
> > out
> > of range error when I try the following code:
> >
> > Sheets("Sample Selection").Select
> > ActiveSheet.Unprotect
> > Cells(2, 5) = Worksheets("SampleCalc").Cells(3, 45)
> >
> > What am I doing wrong?
> >
> > --
> > JP

>

 
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
Linking cells containing text from one worksheet to a cell with textin another worksheet lizmatthews00774@gmail.com Microsoft Excel Discussion 8 10th Oct 2008 12:58 PM
link a cell in the 'Master' worksheet list to a 'Detail' worksheet =?Utf-8?B?UGF1bCBDb25kcm9u?= Microsoft Excel Programming 12 16th Jul 2006 10:41 PM
Place The Contents Of A Cell From The Active Worksheet Into A Cell On An Inavtive Worksheet Minitman Microsoft Excel Programming 1 25th Feb 2004 04:26 AM
Place The Contents Of A Cell From The Active Worksheet Into A Cell On An Inavtive Worksheet Minitman Microsoft Excel Worksheet Functions 1 25th Feb 2004 04:26 AM
Place The Contents Of A Cell From The Active Worksheet Into A Cell On An Inavtive Worksheet Minitman Microsoft Excel Misc 1 25th Feb 2004 04:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:59 AM.