View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default MACRO TO MULTIPLY AMOUNTS WITH PERCENTAGES

I get the same results you do. Nothing need to be done except run macro.
Macro creates new worksheet "results". If macro is run a 2nd time instead of
creating new worksheet it clears the present "results" worksheet.


Sub calc_results()

'check if worksheet results exists
Found = False
For Each sht In Sheets
If sht.Name = "Results" Then
Found = True
Exit For
End If
Next sht
If Found = True Then
'clear worksheet
Sheets("Results").Cells.Clear
Else
Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = "Results"
End If
'copy head row from form to Results
With Sheets("Form")
.Rows(1).Copy Destination:=Sheets("Results").Rows(1)
Sheets("Results").Range("G1") = "PERIOD"
FormRowCount = 2
ResultsRowCount = 2
Do While .Range("A" & FormRowCount) < ""
For MyMonth = 1 To 12
.Rows(FormRowCount).Copy _
Destination:=Sheets("Results").Rows(ResultsRowCoun t)
Period = Val(Format(Date, "YYYY") & Format(MyMonth, "0#"))
Code = .Range("D" & FormRowCount)
With Sheets("PERCENTAGES DATA")
Set PercentRow = .Columns("A").Find(what:=Code, _
LookIn:=xlValues, lookat:=xlWhole)
If PercentRow Is Nothing Then
MsgBox ("Cannot find Code : " & Code)
Exit Sub
End If
Set PercentCol = .Rows(2).Find(what:=Period, _
LookIn:=xlValues, lookat:=xlWhole)
If PercentCol Is Nothing Then
MsgBox ("Cannot find Period : " & Period)
Exit Sub
End If
PercentNumber = .Cells(PercentRow.Row, PercentCol.Column) / 100
End With
With Sheets("Results")
.Range("G" & ResultsRowCount) = Period
.Range("E" & ResultsRowCount).Formula = _
"=" & PercentNumber & "*Form!E" & FormRowCount
End With
ResultsRowCount = ResultsRowCount + 1
Next MyMonth
FormRowCount = FormRowCount + 1
Loop
End With
Sheets("Results").Columns("A:G").Columns.AutoFit
End Sub


"K" wrote:

Hi all, Please see the link below where i have uploded my Sheet.

http://www.savefile.com/files/1535694

I uploded my file as i don' t think i can explain my question here. i
have put my question in above uploaded excel file clearly. Please can
any body help as it is very important for my project which i am doing
for my job. If any friend can help it will much appricated.