Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Can a variable be used in a Worksheet().Activate method

I am needing to place data into different worksheets depending on choices
from the user. I am needing to activate the worksheets based on those
choices. I was using the folowing code but am running into problems, and am
not sure how to get it to work.

'Day is row to place info in
'Movie is the name of the movie for that time
'PCount is the Performance Count for that time
Dim Day As Integer
Dim PCount As Integer
Dim Movie As Integer

Private Sub cmdApply_Click()
Range("A3").Select
Day = ActiveCell.Value + 3
'9am
Range("C5").Select
Movie = ActiveCell.Value
Range("C3").Select
PCount = ActiveCell.Value
Worksheets(Movie).Active
Range("C" & Day).Select
ActiveCell.Value = PCount

the movie variable has been done as a integer with the sheet index and as a
string with the sheet name both having problems. Any help is appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Can a variable be used in a Worksheet().Activate method

I have changed the way I need this to operate I need to clear out the values
on the same time and day on the other sheets so I changed it to look like
this, how can I get this to work?

For X = 1 To ActiveWorkbook.Sheets.Count
Worksheets(X).Active
Range("C" & Day).Select
If X = Movie Then
ActiveCell.Value = PCount
Else
ActiveCell.Value = 0
End If
Next X


The Worksheets(X).Active is where the error happens, how can I accomplish
this otherwise?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Can a variable be used in a Worksheet().Activate method

Try this...

dim wks as worksheet

for each wks in worksheets
if wks.name = "Movie" then
wks.Range("C" & Day) = PCount
else
wks.Range("C" & Day) = 0
end if
next wks
--
HTH...

Jim Thomlinson


"Brad Sumner" wrote:

I have changed the way I need this to operate I need to clear out the values
on the same time and day on the other sheets so I changed it to look like
this, how can I get this to work?

For X = 1 To ActiveWorkbook.Sheets.Count
Worksheets(X).Active
Range("C" & Day).Select
If X = Movie Then
ActiveCell.Value = PCount
Else
ActiveCell.Value = 0
End If
Next X


The Worksheets(X).Active is where the error happens, how can I accomplish
this otherwise?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Can a variable be used in a Worksheet().Activate method

Instead of using active sheets and active cells how about using the actual
sheet code names. In the VB explorer you see a listing of all of the sheets,
forms and modules. Double clicking on a sheet or moduel takes you to the code
for that sheet or module. At this point ensure that the properties is visible
(View - Properties). The first item in the list of prpoerties for a sheet is
(Name). This is the code name of the sheet and it will say something like
Sheet1. You can change it and then reference the sheet directly in code. As a
standard I always premise my sheet code names with sht so you could have
names like shtMovies and shtHome. Once this is done in the code window you
can have code like this...

Private Sub cmdApply_Click()
Day = shtHome.Range("A3").value + 3
'9am
Movie = shtHome.Range("C5").value
PCount = shtHome.Range("C3").value
shtMovies.Range("C" & Day).value = PCount


--
HTH...

Jim Thomlinson


"Brad Sumner" wrote:

I am needing to place data into different worksheets depending on choices
from the user. I am needing to activate the worksheets based on those
choices. I was using the folowing code but am running into problems, and am
not sure how to get it to work.

'Day is row to place info in
'Movie is the name of the movie for that time
'PCount is the Performance Count for that time
Dim Day As Integer
Dim PCount As Integer
Dim Movie As Integer

Private Sub cmdApply_Click()
Range("A3").Select
Day = ActiveCell.Value + 3
'9am
Range("C5").Select
Movie = ActiveCell.Value
Range("C3").Select
PCount = ActiveCell.Value
Worksheets(Movie).Active
Range("C" & Day).Select
ActiveCell.Value = PCount

the movie variable has been done as a integer with the sheet index and as a
string with the sheet name both having problems. Any help is appreciated.

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
Activate method of Worksheet class fails in Excel 2000 Chris Bloom Excel Discussion (Misc queries) 3 September 10th 05 12:05 AM
Activate method of OLEObject failed jose luis Excel Programming 0 June 3rd 05 04:55 AM
Reference to a variable in windows(???).Activate John Baker Excel Programming 7 July 13th 04 02:04 PM
How to activate a file when the filename is represented by a string variable news.sintef.no Excel Programming 4 February 6th 04 02:17 PM
why error for activate method Young-Hwan Choi Excel Programming 2 December 10th 03 08:31 AM


All times are GMT +1. The time now is 01:07 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"