+ Reply to Thread
Results 1 to 5 of 5

VBA Code for Repeating An action

  1. #1
    Registered User
    Join Date
    09-20-2012
    Location
    peshawar
    MS-Off Ver
    Excel 2007
    Posts
    3

    VBA Code for Repeating An action

    Hi everybody i m new to vba plz help me regarding following macro which i want to apply on all excel files in that folder.

    Thanks in advance.




    Sub Macro1()
    '
    ' Macro1 Macro
    '

    '
    Workbooks.Open Filename:="D:\Aziz\Office Files\Workbook 1.xlsx"
    Range("A2:D2").Select
    Selection.Copy
    ActiveWindow.Close
    Range("A2").Select
    ActiveSheet.Paste
    Range("A3").Select
    Workbooks.Open Filename:="D:\Aziz\Office Files\workbook 2.xlsx"
    Range("A2:D2").Select
    Selection.Copy
    ActiveWindow.Close
    ActiveSheet.Paste
    Range("A4").Select
    Workbooks.Open Filename:="D:\Aziz\Office Files\Workbook 3.xlsx"
    Range("A2:D2").Select
    Selection.Copy
    ActiveWindow.Close
    ActiveSheet.Paste
    Range("A5").Select


    End Sub
    Last edited by aujan; 08-04-2013 at 11:15 PM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: VBA Code for Repeating An action

    Hi, aujan,

    maybe add code-tags when displaying a procedure here in the forum.

    Maybe give this code a try:
    Please Login or Register  to view this content.
    Please alter the name of the sheet to which to write (I assumed it is called Sheet1).

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,787

    Re: VBA Code for Repeating An action

    A macro like this perhaps?

    Please Login or Register  to view this content.
    If you are copying formulas from the other workbook change "Paste:=xlPasteAll" to "Paste:=xlValues"

    Alf

  4. #4
    Registered User
    Join Date
    09-20-2012
    Location
    peshawar
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA Code for Repeating An action

    Thanks buddy, Thanks a lot

  5. #5
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: VBA Code for Repeating An action

    @aujan,

    Looks like your query has been solved, but please follow the forum rules and apply code tags.
    HTH
    Regards, Jeff

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. can anyone help with repeating the same action on different ranges?
    By Angol in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-12-2005, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1