Hi and welcome to ExcelForum,
Your post is fine, but please make sure you read the forum rules for future reference.
We are not allowed to answer your posts if the rules aren't followed, especially if you are posting code samples (CODE TAGS are needed): http://www.excelforum.com/forum-rule...rum-rules.html
Cells(Rows.Count, 1).End(xlUp).Row returns the number of the last row with data in Column 'A'. See the following for a better explanation than I can do:
http://www.globaliconnect.com/excel/...=79&Itemid=475
LBound and UBound are used to find the lower and upper bounds for an array. Consider the following example:
Option Explicit
Sub ArrayExample()
Dim a(1 To 3) As Long
Dim b(5 To 7) As Long
Dim i As Long
Dim iMaxIndexForC As Long
'Static arrays a and b
a(1) = 1
a(2) = 3
a(3) = 5
For i = 1 To 3
Debug.Print "a(" & i & ") = " & a(i) 'Outputs results in Immediate Window (CTRL G)
Next i
b(5) = 7
b(6) = 8
b(7) = 9
For i = 5 To 7
Debug.Print "b(" & i & ") = " & b(i) 'Outputs results in Immediate Window (CTRL G)
Next i
For i = LBound(a) To UBound(a)
Debug.Print "a(" & i & ") = " & a(i) 'Outputs results in Immediate Window (CTRL G)
Next i
For i = LBound(b) To UBound(b)
Debug.Print "b(" & i & ") = " & b(i) 'Outputs results in Immediate Window (CTRL G)
Next i
'Dynamic array c
Dim c() As Integer
iMaxIndexForC = 0
For i = 1 To 6
iMaxIndexForC = iMaxIndexForC + 1
If iMaxIndexForC = 1 Then
ReDim c(1 To iMaxIndexForC) 'Redim sets the array indices and clears the values in the array
Else
ReDim Preserve c(1 To iMaxIndexForC) 'Redim 'Preserve' sets the array indices and keeps existing values in the array
End If
c(iMaxIndexForC) = i * 3
Next i
For i = LBound(c) To UBound(c)
Debug.Print "c(" & i & ") = " & c(i) 'Outputs results in Immediate Window (CTRL G)
Next i
End Sub
Additional tips:
To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx
Debugger Secrets:
a. Press 'F8' to single step (goes into subroutines and functions).
b. Press SHIFT 'F8' to single step OVER subroutines and functions.
c. Press CTRL 'F8' to stop at the line where the cursor is.
d. 'Left Click' the margin to the left of a line to set (or clear) a BREAKPOINT.
e. Press CTRL 'G' to open the IMMEDIATE WINDOW. 'debug.print' statements send their
output to the IMMEDIATE WINDOW.
f. Select View > Locals to see all variables while debugging.
g. To automatically set a BREAKPOINT at a certain location put in the line:
'Debug.Assert False'
h. To conditionally set a BREAKPOINT at a certain location put in lines similar to:
if i >= 20 and xTV20 > 99.56 then
Debug.Assert False
endif
i. A variable value will be displayed by putting the cursor over the variable name.
I hope this helps.
Lewis
Bookmarks