Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all, Please see the macro below which is sent to me by one of
online friend Sub MultAmt() Const x = 12 Dim i As Integer Dim LRow As Long Dim rng As Range, c As Range Dim rng2 As Range, c2 As Range LRow = Sheets("FORM").Cells(Rows.Count, "A").End(xlUp).Row Set rng = Sheets("FORM").Range("D2:D" & 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 c In rng LRow = Sheets("RESULT BY MACRO").Cells(Rows.Count, "A").End(xlUp).Row c.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:D" & LRow) LRow = Sheets("PERCENTAGES DATA").Cells(Rows.Count, "A").End(xlUp).Row Set rng2 = Sheets("PERCENTAGES DATA").Range("A3:M" & LRow) i = 2 For Each c In rng c.Offset(, 1).Value = c.Offset(, 1).Value * _ (Application.WorksheetFunction.VLookup(c.Value, rng2, i, False) / 100) c.Offset(, 3).Value = Sheet1.Cells(2, i).Value If i = 13 Then i = 2 Else i = i + 1 End If Next End Sub my question is that in macro above where it say For Each c In rng c.Offset(, 1).Value = c.Offset(, 1).Value * _ (Application.WorksheetFunction.VLookup(c.Value, rng2, i, False) / 100) What code should i add which should do the job if c.Offset(, 1).Value * _ (Application.WorksheetFunction.VLookup(c.Value, rng2, i, False) / 100) = #N/A Then Msgbox "not found" & (code number which is not found) Exit Sub Else c.Offset(, 1).Value = c.Offset(, 1).Value * _ (Application.WorksheetFunction.VLookup(c.Value, rng2, i, False) / 100) to more understand my question you can check the file which i have uploaded ( http://www.savefile.com/files/1535694 ) and you can put the macro above in Module of that sheet. The macro above workes perfectly fine i just need to know how can i add Msgbox line which i mention above. Please if any friend can help |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Msgbox Code Help Please.... | Excel Discussion (Misc queries) | |||
Code for MsgBox | Excel Programming | |||
VBA code using if then and msgbox | Excel Discussion (Misc queries) | |||
Problem with Msgbox Code | Excel Programming | |||
syntax for code in MsgBox()? | Excel Programming |