Need help defining variable in Visual Basic please

  Newuser3443 11:24 12 Oct 05

I am using VB 6.3

I have a macro than calls a number of subroutines. The 1st macro includes the line.....

numsheets = sheets.count

which gives me the number of worksheets.

How do I declare numsheets as a variable so that I can use this result in the other subroutines?

I have very little experience of VB, so in the simplest terms possible please.

Thanks for reading this and for any assistance you can offer.


  johnnyrocker 11:32 12 Oct 05

i think you are likely to get a much better response if you post in web design forum.


  Newuser3443 11:33 12 Oct 05

will try there - thank you Johnny

  Simsy 12:40 12 Oct 05

the web design forum is NOT the place for this query???


You need to declare the variable first using the line;

Dim numsheets as Integer

The fact that you mention worksheets leads me to think that perhaps you are working in Excel, and in fact it is VBA you are using. Is that correct? (Not that it would make a difference to this specific question!)



  Monoux 12:44 12 Oct 05

You need to declare your variable as Public otherwise it will only operate within its own subroutine and its value will not be available to other routines.

  VoG II 21:36 12 Oct 05

You need to Dim it at the top of the module, before any Sub, Function etc.

If it is to be used by routines in other modules then you need to declare it as Public.

Is this VB or VBA?

This thread is now locked and can not be replied to.

Surface Pro 5 News - release date, UK price, features, specs

Gear VR vs. Daydream: Which delivers the best VR experience?

Best Mac antivirus 2017