Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using variables in cell values

Status
Not open for further replies.

drimades

IS-IT--Management
Nov 8, 2004
221
MK
How can I use variables to express the addresses of the cells in Excel? How can I use them in for loops?
 
You can do all of that in the VB Editor, using VBA (Visual Basic for Applications).

If you have specific questions along those lines, feel free to ask over in forum707

For an example:
Code:
Private Sub TestSomeCode()
  Dim wb As Workbook
  Dim ws As Worksheet
  Dim r as Range
  Dim x as Long [green]'rows[/green]
  Dim y as Long [green]'columns[/green]
  
  Set wb = ActiveWorkbook
  Set ws = wb.ActiveSheet
  
  For x = 1 To 10
    For y = 1 To 10
      Set r = ws.Cells(x, y)
      MsgBox "The cell at Range " & r & " is holding the value, " & r.Value
    Next y
  Next x
  
  x = 0
  y = 0
  Set r = Nothing
  Set ws = Nothing
  Set wb = Nothing
End Sub

If you have something you specifically want to do, or are not sure of, and it needs be done this way, then I'd highly suggest you ask it in the above mentioned forum.

--

"If to err is human, then I must be some kind of human!" -Me
 



Check out Named Ranges.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top