Call macro from one macro to another macro

satya12

Board Regular
Joined
Oct 19, 2021
Messages
70
Office Version
  1. 2016
Platform
  1. Windows
Hi All,
I wrote the code with 1000+ line , but when i add some lines and run its getting Procedure is too large. so i want to create another macro in that procedure , i created one macro. but my problem is in the macro1 i used for loop in the for loop some of the process run, after call macro2 do the process, come to macro1 do the second iteration.
but in the macro when i try to putting the "i" which is macro1 for loop variable, its not accepting, i tried create another for loop for macro2 but it is taking all iteartions in the macro2 itself.
but i want to process row by row with 2 macros, can you please help me.
i am attaching macro1 code and macro2 code
VBA Code:
Sub ENT_MACRO()
    Dim ENTPrice As Workbook
    Dim ENTPricews As Worksheet
    Dim ENTCheat As Workbook
    Dim ENTCheatws As Worksheet
    Dim ENTMacro As Workbook
    Dim ENTMacrows As Worksheet
    Dim HR As String
    Dim HR1 As String
    
    Dim Weight As String
    Dim Weight1 As Double
    Dim Weight2 As String
    Dim PLfilter As String
    Dim rngcell As Range
    Dim Condition As Range
    Dim i As Long
    Dim PN As String
    Dim PN1 As String
    Dim PN2 As String
    Dim PN3 As String
    Dim PN4 As String
    
    Set ENTPrice = Workbooks("HP ENT Price book.xlsx")
    Set ENTPricews = ENTPrice.Sheets("DailyPurchasePrice")
    Set ENTCheat = Workbooks("HPE SKU Matrix.xlsx")
    Set ENTCheatws = ENTCheat.Sheets("NEW MATRIX")
    Set ENTMacro = Workbooks("ENT.xlsm")
    Set ENTMacrows = ENTMacro.Sheets("Sheet1")
    ENTMacrows.Rows("2:" & Rows.Count).Delete
    a = ENTPricews.Range("F" & Rows.Count).End(xlUp).Row
    
    For i = 2 To a
        ENTMacrows.Range("B" & i).Value = ENTPricews.Range("F" & i).Value
        HP = "HP-"
        ENTMacrows.Range("O" & i).Value = HP & ENTPricews.Range("G" & i).Value
    'Short  Description
        ENTMacrows.Range("C" & i).Value = ENTPricews.Range("J" & i).Value
    'Long Description
        ENTMacrows.Range("D" & i).Value = ENTPricews.Range("I" & i).Value
    'Product Classification
        ENTMacrows.Range("G" & i).Value = ENTPricews.Range("W" & i).Value
    'List Price
        ENTMacrows.Range("AC" & i).Value = ENTPricews.Range("L" & i).Value
    'Net Price
        ENTMacrows.Range("AB" & i).Value = ENTPricews.Range("O" & i).Value
    
Call Autofill
    
    Next i

End Sub
[CODE=vba]
Public Sub Autofill()
    Set ENTPrice = Workbooks("HP ENT Price book.xlsx")
    Set ENTPricews = ENTPrice.Sheets("DailyPurchasePrice")
    Set ENTCheat = Workbooks("HPE SKU Matrix.xlsx")
    Set ENTCheatws = ENTCheat.Sheets("NEW MATRIX")
    Set ENTMacro = Workbooks("ENT.xlsm")
    Set ENTMacrows = ENTMacro.Sheets("Sheet1")
    
   a = ENTPricews.Range("F" & Rows.Count).End(xlUp).Row
   For i = 2 To a

    'PL Filtering
    PLfilter = ENTPricews.Range("G" & i).Value
    ENTCheatws.Range("$A$1 : $BA$1000000").AutoFilter Field:=1, Criteria1:=PLfilter

    With ENTCheatws
        For Each Condition In .Range("D2", .Cells(.Rows.Count, "D").End(xlUp)).SpecialCells(xlCellTypeVisible)
            If Condition.Value = "CTO or FIO must be in the description. Item has weight (0.1 pound or more) We must convert Kgs into Lbs" Then
                If InStr(ENTMacrows.Range("C" & i).Value, "CTO") > 0 Or InStr(ENTMacrows.Range("C" & i).Value, "FIO") > 0 Then
                    If ENTPricews.Range("AJ" & i).Value <> "" And IsNumeric(ENTPricews.Range("AJ" & i).Value) And ENTPricews.Range("AJ" & i).Value > 0.1 Then
                        Weight1 = ENTPricews.Range("AJ" & i).Value
                        ENTMacrows.Range("P" & i).Value = Weight1 * 2.20462262
                        ENTMacrows.Range("U" & i).NumberFormat = "@"
                        ENTMacrows.Range("K" & i).NumberFormat = "@"
                        ENTMacrows.Range("A" & i).Value = Condition.Offset(0, 18).Value
                        ENTMacrows.Range("J" & i).Value = Condition.Offset(0, 9).Value
                        ENTMacrows.Range("K" & i).Value = Condition.Offset(0, 10).Value
                        ENTMacrows.Range("L" & i).Value = Condition.Offset(0, 11).Value
                        ENTMacrows.Range("T" & i).Value = Condition.Offset(0, 18).Value
                        ENTMacrows.Range("U" & i).Value = Condition.Offset(0, 19).Value
                        ENTMacrows.Range("X" & i).Value = Condition.Offset(0, 22).Value
                        ENTMacrows.Range("Y" & i).Value = Condition.Offset(0, 23).Value
                        ENTMacrows.Range("Z" & i).Value = Condition.Offset(0, 24).Value
                        ENTMacrows.Range("AF" & i).Value = Condition.Offset(0, 30).Value
                        ENTMacrows.Range("AI" & i).Value = Condition.Offset(0, 33).Value
                        ENTMacrows.Range("AL" & i).Value = Condition.Offset(0, 36).Value
                        ENTMacrows.Range("AM" & i).Value = Condition.Offset(0, 37).Value
                        ENTMacrows.Range("AN" & i).Value = Condition.Offset(0, 38).Value
                        ENTMacrows.Range("AO" & i).Value = Condition.Offset(0, 39).Value
                        ENTMacrows.Range("AP" & i).Value = Condition.Offset(0, 40).Value
                        ENTMacrows.Range("AQ" & i).Value = Condition.Offset(0, 41).Value
                        Exit For
                    End If
                End If
Else
                ENTMacrows.Range("U" & i).NumberFormat = "@"
                    ENTMacrows.Range("K" & i).NumberFormat = "@"
                    ENTMacrows.Range("A" & i).Value = Condition.Offset(0, 18).Value
                    ENTMacrows.Range("J" & i).Value = Condition.Offset(0, 9).Value
                    ENTMacrows.Range("K" & i).Value = Condition.Offset(0, 10).Value
                    ENTMacrows.Range("L" & i).Value = Condition.Offset(0, 11).Value
                    ENTMacrows.Range("T" & i).Value = Condition.Offset(0, 18).Value
                    ENTMacrows.Range("U" & i).Value = Condition.Offset(0, 19).Value
                    ENTMacrows.Range("X" & i).Value = Condition.Offset(0, 22).Value
                    ENTMacrows.Range("Y" & i).Value = Condition.Offset(0, 23).Value
                    ENTMacrows.Range("Z" & i).Value = Condition.Offset(0, 24).Value
                    ENTMacrows.Range("AF" & i).Value = Condition.Offset(0, 30).Value
                    ENTMacrows.Range("AI" & i).Value = Condition.Offset(0, 33).Value
                    ENTMacrows.Range("AL" & i).Value = Condition.Offset(0, 36).Value
                    ENTMacrows.Range("AM" & i).Value = Condition.Offset(0, 37).Value
                    ENTMacrows.Range("AN" & i).Value = Condition.Offset(0, 38).Value
                    ENTMacrows.Range("AO" & i).Value = Condition.Offset(0, 39).Value
                    ENTMacrows.Range("AP" & i).Value = Condition.Offset(0, 40).Value
                    ENTMacrows.Range("AQ" & i).Value = Condition.Offset(0, 41).Value
            End If
        Next
    End With
Next i
End Sub
[/CODE]
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
In the first macro change:
VBA Code:
Call Autofill
to
VBA Code:
Call Autofill(i)
in the second macro change:
VBA Code:
Public Sub Autofill()
to
VBA Code:
Public Sub Autofill(i As Long)
then comment out these two lines in the seocnd macro:
VBA Code:
'   For i = 2 To a
and
VBA Code:
'Next i
 
Upvote 0
Solution

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top