need a macro explaining
getting a few errors when i run this one...
"JLGWhiz" wrote:
Option Explicit
'Requires all variables to be declared before runtime
Sub Summary() 'Title of procedure
Dim ws As Worksheet 'Declares ws as worksheet object
Dim i As Long, j As Long, rw As Long
'Declares three individual variables as long integers (numeric)
Set ws = Sheets("Summary") 'Sets ws variable to an object value
For j = 1 To 7 'Sets up a For loop and its parameter limits
rw = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
'assigns a value to the rw variable for last row number
'in column A
For i = 1 To 7 'Starts a second embedded For...Next loop
ws.Cells(rw, i).Value = Sheets(CStr(j)).Cells. _
'I do not know why the CStr function is used here but it
'converts the value of j to a string number. Maybe the
'sheet is named as a number. This set a cell in the last
'row equal to a value in row 2 of the same column.
Find(ws.Cells(1,i)).Offset(1).Value 'Looks the a value equal to
'the value in row 2 of the same column
Sheets(CStr(j)).Cells.Find(ws.Cells(1,
i)).Offset(1).ClearContents
'Deleteds the value in the cell just found.
Next i 'Sends to next iteration until limit is reached
Next j 'Sends to next iteration until limit is reached
End Sub 'Kaput
"project manager" wrote in
message ...
is it possible for someone to annotate this macro so i can understand what
its doing and try to learn from it.
Option Explicit
Sub Summary()
Dim ws As Worksheet
Dim i As Long, j As Long, rw As Long
Set ws = Sheets("Summary")
For j = 1 To 7
rw = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
For i = 1 To 7
ws.Cells(rw, i).Value = Sheets(CStr(j)).Cells.Find(ws.Cells(1,
i)).Offset(1).Value
Sheets(CStr(j)).Cells.Find(ws.Cells(1,
i)).Offset(1).ClearContents
Next i
Next j
End Sub
|