Macro 1, Macro 2, Macro 3 > after each other! Need HELP!

NetZorro

New Member
Joined
Aug 23, 2005
Messages
27
Would REALLY need som help.
Today i use 3 macro.
I want to combine them.. i have search and read the form for so long now, and cant find an answare. Please help me!! Need this badly!

Macro 1

Code:
Sub Search_and_Add_To_LagerLista_()
'
' Makro1 Makro
' Söker o kopiera in värden efter EAN-coder som redan finns i bladet "LagerLista"
'
' Kortkommando: Ctrl+r
'
'Del1: Bla. så börja dem med att placera sig längst upp, i det övre fönstret, och markera även
'kolumn E.  Efter det så letar den efter ett värde från C4, i hela Kolumn E
   With Sheets("LagerLista")
    Sheets("LagerLista").Select
    ActiveWindow.Panes(1).Activate
    Columns("E:E").Select
   .Columns("E:E").Find( _
            What:=Sheets("EAN_Inlasning").Range("C4").Value, _
            After:=ActiveCell, _
            LookIn:=xlValues, _
            LookAt:=xlWhole, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, _
            MatchCase:=False, _
            SearchFormat:=False).Select
  End With
  
  'START av addering utav Antal
    ActiveCell.Offset(0, 3).Range("A1").Select
    Sheets("EAN_Inlasning").Select 'Förflyttas till EAN_Inlasning
    Range("B4").Select 'B4 dvs. Antal markeras
    Application.CutCopyMode = False
    Selection.Copy 'B4 dvs. Antal kopieras
    Sheets("LagerLista").Select 'Förflyttas till LagerLista
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlAdd, SkipBlanks:= _
        False, Transpose:=False 'Värdet ifrån B4 adderas med det antalet längst till höger
    '****
 
Sheets("LagerLista").Select   'LevListor markeras (kan ev. ta bort) och kolumn E Markeras (för säkerhets skull, behövdes innan jag lade variablen högre upp
Application.CutCopyMode = False
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Sheets("EAN_Inlasning").Select   'Bladet EAN_Inlasning markeras
Range("C4").Select  'Nu är allt klart, och markören står på C4, och redo för att ändras!
End Sub

Macro 2

Code:
Sub CopyEAN_SearchLevListor_PasteLagerLista()

'
' CopyEAN_SearchLevListor_PasteLagerLista Maro
' Makrot inspelat 2005-08-14
'
' Kortkommando: Ctrl+q
'

'Nedre 4 rader bara ser till att markören står på rätt sätt i LagerLista-bladet, eftersom det är viktigt.
Sheets("LagerLista").Select   'Bladet LagerLista markeras
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select

'Går tillbaka till bladet EAN_Inlasning, där sökvärdet finns.
Sheets("EAN_Inlasning").Select
Range("C4").Select

'Del2: Bla. så börja dem med att placera sig längst upp, i det övre fönstret, och markera även
'kolumn E.  Efter det så letar den efter ett värde från C4, i hela Kolumn E
   With Sheets("LevListor")
    Sheets("LevListor").Select
    ActiveWindow.Panes(1).Activate
    Columns("E:E").Select
   .Columns("E:E").Find( _
            What:=Sheets("EAN_Inlasning").Range("C4").Value, _
            After:=ActiveCell, _
            LookIn:=xlValues, _
            LookAt:=xlWhole, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, _
            MatchCase:=False, _
            SearchFormat:=False).Select
   End With
   
Selection.EntireRow.Select  'Här markeras den rad som hittar en "Match"
Selection.Copy  'Raden som var en "Match" kopieras
Sheets("LagerLista").Select     'Bladet LagerLista markeras
ActiveSheet.Paste      'Det som kopierades från Kolumn E, klistas in.
Selection.End(xlToRight).Select 'Markör flyttas så mycket det går till höger
ActiveCell.Offset(0, 1).Range("A1").Select 'Markör flyttas yttligare ett steg, Till Antal kolumnen
ActiveCell.FormulaR1C1 = "1" 'Antal får "grundvärdet" 1
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select   'Markören har nu flyttats ner så att nästa inklistring inte kommer ovanpå, utan under
Application.CutCopyMode = False
Sheets("EAN_Inlasning").Select   'Bladet EAN_Inlasning markeras
Range("C4").Select  'Nu är allt klart, och markören står på B2, och redo för att ändras!
    Sheets("EAN_Inlasning").Select
    Range("C4").Select
    Selection.Copy
    Sheets("LagerLista").Select
    Range("A1").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
        ActiveCell.FormulaR1C1 = "xxxx"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "xxxx"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "xxxx"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveSheet.Paste '**** av EAN-kopiering
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "xxxx"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "xxxx"
        ActiveCell.Offset(0, 1).Range("A1").Select
        Sheets("EAN_Inlasning").Select
        Range("B4").Select
    Selection.Copy
    Sheets("LagerLista").Select
        ActiveSheet.Paste '**** av Antal-kopiering
    Range("A1").Select
        Selection.End(xlDown).Select
        ActiveCell.Offset(0, 1).Range("A1").Select
End Sub

Macro 2

Code:
Sub CopyNewToEAN_LagerLista()
'
' CopyNewToEAN_LagerLista Makro
' Makrot inspelat 2005-08-25 av Daniel Persson
'
' Kortkommando: Ctrl+t
'
    Sheets("EAN_Inlasning").Select
    Range("C4").Select
    Selection.Copy
    Sheets("LagerLista").Select
    Range("A1").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
        ActiveCell.FormulaR1C1 = "xxxx"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "xxxx"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "xxxx"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveSheet.Paste '**** av EAN-kopiering
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "xxxx"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "xxxx"
        ActiveCell.Offset(0, 1).Range("A1").Select
        Sheets("EAN_Inlasning").Select
        Range("B4").Select
    Selection.Copy
    Sheets("LagerLista").Select
        ActiveSheet.Paste '**** av Antal-kopiering
    Range("A1").Select
        Selection.End(xlDown).Select
        ActiveCell.Offset(0, 1).Range("A1").Select
End Sub

Pleeessse...... bare with me!
/NetZorro
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
this should work

Code:
Sub RunAllMacros()
  Search_and_Add_To_LagerLista_
  CopyEAN_SearchLevListor_PasteLagerLista
  CopyNewToEAN_LagerLista
End Sub
 
Upvote 0
Where should i put that?

Should i make a new Macro, containing all 3 macros, with

Code:
Sub RunAllMacros() 
  Search_and_Add_To_LagerLista_ 
  CopyEAN_SearchLevListor_PasteLagerLista 
  CopyNewToEAN_LagerLista 
End Sub

At the top?

Tanks for help
/NetZorro
 
Upvote 0
sure, it doesn't matter where you put it (you probably want to put it in the same module), but the important thing is to put a key reference to it that you like, as you've done with the other macros
 
Upvote 0
I still get an error message, as i use to, when the macro don't find an match. Then it Stops, says

Runerror nr '91' Objecvariable or With-blockvariable not defiend

If i take "faultsearch" The following sentence in the macro is yellohighlighted:

Code:
  .Columns("E:E").Find( _
            What:=Sheets("EAN_Inlasning").Range("C4").Value, _
            After:=ActiveCell, _
            LookIn:=xlValues, _
            LookAt:=xlWhole, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, _
            MatchCase:=False, _
            SearchFormat:=False).Select

Ahhh... What should i do??
Help Please!
 
Upvote 0
without reading all the code....maybe you could try putting

ON ERROR RESUME NEXT

at the start of your macro
 
Upvote 0
Angels in the SKY... we are soon there!...

YES.. that did the trick.. but i do not want the 3 macro to run, if there is a match in the 2 macro.

Because, the 3 macro, should only work, if Macro 1, is not match,
and Macro 2 is no Match, then Macro 3 starts, (Witch copies the EAN-code) to a new row, in sheet "LagerLista".

Right now.. it prints both Macro 2 (if its a hit) and then Macro 3 aswell.

any ideas.!
 
Upvote 0
NetZorro

Is what you are looking for actually being found?

If it isn't then it will cause that error.

By the way you don't actually need to select ranges/sheets etc to work with them.
 
Upvote 0
NetZorro said:
Angels in the SKY... we are soon there!...

YES.. that did the trick.. but i do not want the 3 macro to run, if there is a match in the 2 macro.

Because, the 3 macro, should only work, if Macro 1, is not match,
and Macro 2 is no Match, then Macro 3 starts, (Witch copies the EAN-code) to a new row, in sheet "LagerLista".

Right now.. it prints both Macro 2 (if its a hit) and then Macro 3 aswell.

any ideas.!

see if this works...

in module 2 put at the top

ON ERROR EXIT SUB

not sure if it'll work though b/c it may only exit macro2 not the consolidated macro....
 
Upvote 0

Forum statistics

Threads
1,223,942
Messages
6,175,544
Members
452,652
Latest member
eduedu

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