+ Reply to Thread
Results 1 to 14 of 14

Want To Join Many Code With One Button With One InputBox

Hybrid View

  1. #1
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Thumbs up Want To Join Many Code With One Button With One InputBox

    Hello Sir :

    I Have This 4 Code Working With Different Sheet Of One Workbook
    Code 1
    Sheet Name ("OF $")
    Sub CopyPasteDataToAnotherWorkbook()
    Dim sFile As String
    
    Application.ScreenUpdating = False
    
    Range("E6:J26").Copy
    
    sFile = InputBox("which wrk book u want to copy?")
    
    Workbooks.Open ("z:\42766\jan 2 dec 2014\1.3.14\" & sFile & ".xlsm")
        Worksheets("OF $").Range("H6:M26").PasteSpecial xlPasteAll
    ActiveWorkbook.Close SaveChanges:=True
    
    Application.ScreenUpdating = True
    
    MsgBox "Data pasted successfully", vbInformation, "Task Completed"
    
    End Sub
    Code 2
    Sheet Name ("OL $")
    Sub CopyPasteDataToAnotherWorkbook2()
    Dim sFile As String
    
    Application.ScreenUpdating = False
    
    Range("D6:D14").Copy
    
    sFile = InputBox("which wrk book u want to copy?")
    
    Workbooks.Open ("z:\42766\jan 2 dec 2014\1.3.14\" & sFile & ".xlsm")
        Worksheets("OL $").Range("V6:V14").PasteSpecial xlPasteAll
    ActiveWorkbook.Close SaveChanges:=True
    
    Application.ScreenUpdating = True
    
    MsgBox "Data pasted successfully", vbInformation, "Task Completed"
    
    End Sub
    Code 3
    Sheet Name ("OF EXT")
    Sub CopyPasteDataToAnotherWorkbook3()
    Dim sFile As String
    
    Application.ScreenUpdating = False
    
    Range("F5:Z142").Copy
    
    sFile = InputBox("which wrk book u want to copy?")
    
    Workbooks.Open ("z:\42766\jan 2 dec 2014\1.3.14\" & sFile & ".xlsm")
        Worksheets("OF EXT").Range("AA5:AU142").PasteSpecial xlPasteAll
    ActiveWorkbook.Close SaveChanges:=True
    
    Application.ScreenUpdating = True
    
    MsgBox "Data pasted successfully", vbInformation, "Task Completed"
    
    End Sub
    Code 4
    Sheet Name ("OL EXT")
    Sub CopyPasteDataToAnotherWorkbook4()
    Dim sFile As String
    
    Application.ScreenUpdating = False
    
    Range("C5:BP50").Copy
    
    sFile = InputBox("which wrk book u want to copy?")
    
    Workbooks.Open ("z:\42766\jan 2 dec 2014\1.3.14\" & sFile & ".xlsm")
        Worksheets("OL EXT").Range("C51:BP96").PasteSpecial xlPasteAll
    ActiveWorkbook.Close SaveChanges:=True
    
    Application.ScreenUpdating = True
    
    MsgBox "Data pasted successfully", vbInformation, "Task Completed"
    
    End Sub
    I Want To Join These All Code..............should work with one click button.....+ one input box for select file using path

    plz help
    Last edited by HaroonSid; 03-09-2014 at 08:55 AM. Reason: solved

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Want To Join Many Code With One Button With One InputBox

    call  CopyPasteDataToAnotherWorkbook
    call CopyPasteDataToAnotherWorkbook2
    call CopyPasteDataToAnotherWorkbook3
    call CopyPasteDataToAnotherWorkbook4
    If solved remember to mark Thread as solved

  3. #3
    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,199

    Re: Want To Join Many Code With One Button With One InputBox

    Hi, haroon2015,

    from what I understand you want to call the procedure from each single sheet and add accordingly to that sheetīs name in the workbook it is being called from:
    Sub CopyPasteDataToAnotherWorkbook()
    Dim vFile As Variant
    Dim strRange As String
    
    Application.ScreenUpdating = False
    
    Select Case ActiveSheet.Name
      Case "OF $"
        strRange = "H6:M26"
        Range("E6:J26").Copy
      Case "OL $"
        strRange = "V6:V14"
        Range("D6:D14").Copy
      Case "OF EXT"
        strRange = "AA5:AU142"
        Range("F5:Z142").Copy
      Case "OL EXT"
        strRange = "C51:BP96"
        Range("C5:BP50").Copy
      Case Else
        Exit Sub
    End Select
    
    vFile = InputBox("which wrk book u want to copy?")
    
    If vFile <> False Then
      Workbooks.Open ("z:\42766\jan 2 dec 2014\1.3.14\" & vFile & ".xlsm")
      Worksheets(ActiveSheet.Name).Range(strRange).PasteSpecial xlPasteAll
      ActiveWorkbook.Close SaveChanges:=True
    End If
    
    Application.ScreenUpdating = True
    
    MsgBox "Data pasted successfully", vbInformation, "Task Completed"
    
    End Sub
    patel45īs suggestion would get the range to copy from the very same sheet.

    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

  4. #4
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Want To Join Many Code With One Button With One InputBox

    dear HaHoBe

    an error
    Run Time Error '1004':

    PateSpecial method of range class failed

    thsnx

  5. #5
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Want To Join Many Code With One Button With One InputBox

    patel45

    thanx for reply........

    in ur code msg box asking for evry time for file name

    i want only one time msgbox for all four code and data paste in one time on four different name sheets

    plz join the code

  6. #6
    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,199

    Re: Want To Join Many Code With One Button With One InputBox

    Hi, haroon2015,

    I would never ask the user for the name of a workbook to type in via Inputbox but use either the xlDialog or GetopenFilename:
    Sub CopyPasteDataToAnotherWorkbook2()
    Dim vFile As Variant
    Dim varSheets As Variant
    Dim varCopyDest As Variant
    Dim varCopyTarg As Variant
    Dim lngCounter As Long
    Dim wb As Workbook
    
    varSheets = Array("OF $", "OL $", "OF EXT", "OL EXT", "C51:BP96")
    varCopyDest = Array("E6:J26", "D6:D14", "F5:Z142", "C5:BP50")
    varCopyTarg = Array("H6:M26", "V6:V14", "AA5:AU142", "C51:BP96")
    
    vFile = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*")
    
    If vFile <> False Then
      Application.ScreenUpdating = False
      On Error Resume Next
      Set wb = Workbooks.Open(vFile)
      If Not wb Is Nothing Then
        For lngCounter = LBound(varSheets) To UBound(varSheets)
          ThisWorkbook.Worksheets(varSheets(lngCounter)).Range(varCopyDest(lngCounter)).Copy
          wb.Worksheets(varSheets(lngCounter)).Range(varCopyTarg(lngCounter)).PasteSpecial xlPasteAll
        Next lngCounter
        wb.Close SaveChanges:=True
        Set wb = Nothing
      Else
        MsgBox "Workbook not found!"
        Application.ScreenUpdating = True
        Exit Sub
      End If
      Application.ScreenUpdating = True
    
      MsgBox "Data pasted successfully", vbInformation, "Task Completed"
    End If
    
    End Sub
    Ciao,
    Holger

  7. #7
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Post Re: Want To Join Many Code With One Button With One InputBox

    dear sir

    i m uploading the my source and destination file

    something is wrong plz check the sample files
    Attached Files Attached Files

  8. #8
    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,199

    Re: Want To Join Many Code With One Button With One InputBox

    Hi, haroon2015,

    something is wrong plz check the sample files
    Agree on that as no code is in the workbook copy.xlsm as it would be needed to run
          ThisWorkbook.Worksheets(varSheets(lngCounter)).Range(varCopyDest(lngCounter)).Copy
    as ThisWorkbook expects the code to be located in exactly that workbook (copy.xlsm).
          Workbooks("copy.xlsm").Worksheets(varSheets(lngCounter)).Range(varCopyDest(lngCounter)).Copy
    would work around that and accept the code in any other workbook except paste.xlsm but I donīt like hardcoding workbook names in the code.

    Ciao,
    Holger

  9. #9
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Want To Join Many Code With One Button With One InputBox

    yes thats what i want..................

    thanx a lot HaHoBe sir


    thanx once again

    its working very well like water

+ 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. add cancel button to inputbox
    By SarahPintal in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2011, 02:27 AM
  2. Inputbox cancel button error.
    By abhay_547 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-05-2010, 06:27 AM
  3. activate cancel button in a inputbox
    By mania112 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-19-2009, 07:09 AM
  4. Inputbox button control + msgbox for empty inputbox
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-30-2009, 12:39 PM
  5. Inputbox - HELP button not displayed
    By little_pea in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2008, 06:03 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