User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 422,984 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,958 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 1712 | Replies: 2 | Solved
Reply
Join Date: Jul 2006
Posts: 2
Reputation: DarkAlex is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
DarkAlex DarkAlex is offline Offline
Newbie Poster

Basic Variables Question

  #1  
Jul 14th, 2006
Hello. This is a very very basic question about variables in range names.
I have quite a few ranges of varying lengths in multiple Excel documents. I want all the ranges standardized and set to the same length, but I don't know what that length will be yet, and it may change, so I'd like to make a variable for it.

This is currently the best I've come up with:

Sub FixEverything()
Dim sh As Worksheet
For Each sh In Worksheets
    sh.Visible = True
Next
 
Dim OutLim As Integer
OutLim = 200
ActiveSheet.Names.Add Name:="RangeNameHere", RefersTo:="=$A$3:$B$OutLim" ' One of these lines per named Array 

    Worksheets(2).Visible = Hide
    Worksheets(4).Visible = Hide
    Worksheets(6).Visible = Hide
    Worksheets(8).Visible = Hide
End Sub
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Posts: 85
Reputation: williamrojas78 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
williamrojas78's Avatar
williamrojas78 williamrojas78 is offline Offline
Junior Poster in Training

Re: Basic Variables Question

  #2  
Jul 14th, 2006
Hi

Are you working with multiple excel documents or with multiple worksheets in the same document. I guess it does not really matter.

i noticed you have an error in your formula, if you want to set a range the worksheets of your workbook do something like this:
For i = 1 To 3
OutLim = 200

    Worksheets(i).Activate

    ActiveSheet.Names.Add Name:="RangeNameHere", RefersTo:="=$A$3:$B$" & OutLim 

Next

that will set the range A3:B200 in the first three sheets.

If you want to do it in all the sheets, do as you did at the beginning: for each sh in workbooks

regards
Reply With Quote  
Join Date: Jul 2006
Posts: 2
Reputation: DarkAlex is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
DarkAlex DarkAlex is offline Offline
Newbie Poster

Re: Basic Variables Question

  #3  
Jul 21st, 2006
Ah, so that's how you do it. Thanks, I didn't realize I could use the & operator in that way. As it turns out, someone decided we were going to do the program in a completely different way anyway, so my question was almost immediately invalidated.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 3:29 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC