View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Mark Ivey[_2_] Mark Ivey[_2_] is offline
external usenet poster
 
Posts: 171
Default CAN ANYBODY PLEASE HELP ME WITH THIS MACRO

I will take a closer look at it this evening when I get home from work...

Mark Ivey

"K" wrote in message
...
On Apr 18, 2:43 am, "Mark Ivey" wrote:
Without seeing the data on your sheet, I can only speculate at what might
work for you...

I found a few mistakes with your code by running it through debug mode...

Here are the fixes I would recommend.

Mark Ivey

Sub test2()
Dim LastRowColD As Long
Dim i, J, k, t As Long

Dim A_Percents(1 To 12) As Integer
Dim MTH(1 To 12) As Long ' changed type due to value being a long
number

MTH(1) = 200801
MTH(2) = 200802
MTH(3) = 200803
MTH(4) = 200804
MTH(5) = 200805
MTH(6) = 200806
MTH(7) = 200807
MTH(8) = 200808
MTH(9) = 200809
MTH(10) = 200810
MTH(11) = 200811
MTH(12) = 200812

A_Percents(1) = 8
A_Percents(2) = 8
A_Percents(3) = 9
A_Percents(4) = 8
A_Percents(5) = 8
A_Percents(6) = 9
A_Percents(7) = 8
A_Percents(8) = 8
A_Percents(9) = 9
A_Percents(10) = 8
A_Percents(11) = 8
A_Percents(12) = 9

LastRowColD = Sheets(1).Range("D1").End(xlDown).Row

k = 2

For i = 2 To LastRowColD
If Cells(i, 4).Value = "A" Then
For J = 1 To UBound(A_Percents)
For t = 1 To UBound(MTH)
Sheets(2).Cells(k, 1).Value = Sheets(1).Cells(i,
1).Value
Sheets(2).Cells(k, 2).Value = Sheets(1).Cells(i,
2).Value
Sheets(2).Cells(k, 3).Value = Sheets(1).Cells(i,
3).Value
Sheets(2).Cells(k, 4).Value = "A"
Sheets(2).Cells(k, 5).Value = (A_Percents(J) / 100) * _
Sheets(1).Cells(i,
5).Value
Sheets(2).Cells(k, 6).Value = Sheets(1).Cells(i,
6).Value
Sheets(2).Cells(k, 7).Value = MTH(t)
k = k + 1
Next
Next ' added a next statement for the second FOR loop
End If
Next

Sheets(2).Cells(1, 1).Value = "AC"
Sheets(2).Cells(1, 2).Value = "CO"
Sheets(2).Cells(1, 3).Value = "FO"
Sheets(2).Cells(1, 4).Value = "CODE"
Sheets(2).Cells(1, 5).Value = "AMT"
Sheets(2).Cells(1, 6).Value = "DETAIL"
Sheets(2).Cells(1, 7).Value = "PERIOD"
End Sub


Thanks for replying Mark. I been struggling to get this answer from
long time. Your macro work fine but it just sligtly giving different
result.
Please see the excel file in link below which I have uploaded on
www.savefile.com. I have explained everything in this file. hope
you'll understand what i am trying to say. Please do reply.

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