Basic Variables Question

Thread Solved

Join Date: Jul 2006
Posts: 2
Reputation: DarkAlex is an unknown quantity at this point 
Solved Threads: 0
DarkAlex DarkAlex is offline Offline
Newbie Poster

Basic Variables Question

 
0
  #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:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Sub FixEverything()
  2. Dim sh As Worksheet
  3. For Each sh In Worksheets
  4. sh.Visible = True
  5. Next
  6.  
  7. Dim OutLim As Integer
  8. OutLim = 200
  9. ActiveSheet.Names.Add Name:="RangeNameHere", RefersTo:="=$A$3:$B$OutLim" ' One of these lines per named Array
  10.  
  11. Worksheets(2).Visible = Hide
  12. Worksheets(4).Visible = Hide
  13. Worksheets(6).Visible = Hide
  14. Worksheets(8).Visible = Hide
  15. End Sub
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 85
Reputation: williamrojas78 is an unknown quantity at this point 
Solved Threads: 4
williamrojas78's Avatar
williamrojas78 williamrojas78 is offline Offline
Junior Poster in Training

Re: Basic Variables Question

 
0
  #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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. For i = 1 To 3
  3. OutLim = 200
  4.  
  5. Worksheets(i).Activate
  6.  
  7. ActiveSheet.Names.Add Name:="RangeNameHere", RefersTo:="=$A$3:$B$" & OutLim
  8.  
  9. 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 Quick reply to this message  
Join Date: Jul 2006
Posts: 2
Reputation: DarkAlex is an unknown quantity at this point 
Solved Threads: 0
DarkAlex DarkAlex is offline Offline
Newbie Poster

Re: Basic Variables Question

 
0
  #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 Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC