If yoiu are so concerned about properly documenting your code you should also
use variables that have MEANING. What are c1 and c2 used for??? compare my
code with your code and look at which code is easier to understand. Well
writeen code has the following
1) Plenty of whitespaces to make it easy to read
2) break complex statements into multiple statements.
3) Use variables theat have meaning.
I had two teaches in college who taught programming. They were
Son-of-a-Bitch. the same BITCH. They were actually brothers. One taught
PASCAL and Fortran and graded based on the amount of comments you had in your
code. the second taught assembly language. He was tougher. He took point
off for too little comments and too much comments. It had to be just right.
He also took off point if you had to many lines of code or too little (if
using tricks to reduce lines made the code confusing). I only got B's in his
course because I used 12 lines of code where he did it in 11 lines.
Sub MultAmt()
Const x = 12
Dim i As Integer
Dim LRow As Long
Dim rng As Range, search_code As Range
Dim rng2 As Range, c2 As Range
LRow = Sheets("FORM").Cells(Rows.Count, "A").End(xlUp).Row
Set codes = Sheets("FORM").Range("D2
" & LRow)
LRow = Sheets("RESULT BY MACRO").Cells(Rows.Count, "A").End(xlUp).Row
If LRow = 1 Then
'do nothing
Else
Sheets("RESULT BY MACRO").Rows("2:" & LRow).Delete
End If
i = 1
For Each search_code In codes
LRow = Sheets("RESULT BY MACRO").Cells(Rows.Count,
"A").End(xlUp).Row
search_code.EntireRow.Copy Sheets("RESULT BY MACRO").Range("A" &
LRow +
i & ":A" & LRow + x)
Next
LRow = Sheets("RESULT BY MACRO").Cells(Rows.Count, "A").End(xlUp).Row
Set rng = Sheets("RESULT BY MACRO").Range("D2
" & LRow)
LRow = Sheets("PERCENTAGES DATA").Cells(Rows.Count, "A").End(xlUp).Row
'change range to column A only
Set code_range = Sheets("PERCENTAGES DATA").Range("A3:A" & LRow)
i = 2
For Each c In rng
set mode_cell = code_range.find(what:=c.value, _
lookin:=xlvalues,lookat:=xlwhole)
if mode_cell is nothing then
msgbox("Cannot find Code : " & c.value)
exit sub
else
Percentage = mode_cell.offset(0,1)/100
end if
c.Offset(, 1).Value = c.Offset(, 1).Value * Percentage
c.Offset(, 3).Value = Sheet1.Cells(2, i).Value
If i = 13 Then
i = 2
Else
i = i + 1
End If
Next
End Sub