VBA for exporting to another predefined workbook

Wowdude

New Member
Joined
Apr 25, 2013
Messages
9
Hi,

I'm putting together some workbooks for my company and looking into how to use VBA to send out work to another workbook.

I already have the code to copy and paste the code into a specified workbook (by destination), but i'm looking for a way to have a selectable drop down menu and by picking a name and then using the macro, the selected data will be cut and pasted into the workbook of the same name as the user picked.

Any ideas?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I have used the following code and it started working perfectly.

It simply runs through a few If statements to see what the C1 cell contains (drop down menu) and uses the relevant workbook linked to that process.

However, now when it gets to the "Paste" section, I get the Run-time error 1004.

Code:
Private Sub CommandButton21_Click()

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    

Dim myRange As Range
Set myRange = Selection
 wb = ActiveWorkbook.Name
 

   If Cells(1, "C") = "Avtar" Then
     Workbooks.Open "C:\Users\ben.hubery\Desktop\Avtar.xlsx"
     Windows(wb).Activate
     Selection.Cut 'define the range to copy

     Windows("Avtar.xlsx").Activate
     Sheets("Sheet1").Select
     Workbooks("Avtar").Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues, _
     Operation:=xlNone, _
     SkipBlanks:=False, _
     Transpose:=False
     Application.CutCopyMode = False
    End If
 

    If Cells(1, "C") = "Ben" Then
     Workbooks.Open "C:\Users\ben.hubery\Desktop\Ben.xlsx"
     Windows(wb).Activate
     Selection.Cut 'define the range to copy

     Windows("Ben.xlsx").Activate
     Sheets("Sheet1").Select
     Workbooks("Ben").Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues, _
     Operation:=xlNone, _
     SkipBlanks:=False, _
     Transpose:=False
     Application.CutCopyMode = False
    End If
 

    If Cells(1, "C") = "Farai" Then
     Workbooks.Open "C:\Users\ben.hubery\Desktop\Farai.xlsx"
     Windows(wb).Activate
     Selection.Cut 'define the range to copy
    
     Windows("Farai.xlsx").Activate
     Sheets("Sheet1").Select
     Workbooks("Farai").Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues, _
     Operation:=xlNone, _
     SkipBlanks:=False, _
     Transpose:=False
     Application.CutCopyMode = False
    End If
     

    If Cells(1, "C") = "Sophie" Then
     Workbooks.Open "C:\Users\ben.hubery\Desktop\Sophie.xlsx"
     Windows(wb).Activate
     Selection.Cut 'define the range to copy
    
     Windows("Sophie.xlsx").Activate
     Sheets("Sheet1").Select
     Workbooks("Sophie").Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues, _
     Operation:=xlNone, _
     SkipBlanks:=False, _
     Transpose:=False
     Application.CutCopyMode = False
    End If
 

 Workbooks(wb).Activate
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,504
Messages
6,125,183
Members
449,212
Latest member
kenmaldonado

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