View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default assigning worksheet variable


Activesheets does not exist. Activesheet does.
I assumed it's just a typo in your post... but typo's in code can be
crucial!

Therefor: ALWAYS start your code modules with
OPTION EXPLICIT
(it will force you to declare your variables before you can use them,
it may look cumbersome... but it's just good practice)


dim str as string
dim wks as worksheet 'this is an OBJECT variable
dim var 'type is not declared = variant


str = "Hi" 'Assign to normal variable officially it's
LET str = "Hi" 'but you're allowed to skip the LET statement

SET wks = Activesheet 'Assign to object variable

'Anytinh can be assinged to a variant but if you're working with an
object you must use SET
var = "Hi"
set var = Activesheet



Same goes for comparing...

use IS for objects

if wks IS nothing
if wks IS thisworkbook.worksheets(1)

use = for values
if str = "hi"
if str = "oops"
if wks.name = "Sheet1"

etc...

search help on DIM and take it from there.




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"?B?U2ltb24gU2hhdw==?="
wrote:

I want to set the variable ws similar to the For statement, but I want
to set it for just the current active sheet.

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets

please help this is not working:

ws = ActiveSheets