Macro used in conjunction with Data Validation

stringfolk

New Member
Joined
Jun 26, 2008
Messages
16
I found this bit of code that the user came up with to run through a data validation list and print each unique page. i'd like to take this code and instead of print, copy and paste values+formats to a new workbook.

can someone to direct me on how?

Sorry everyone...

I just figured it out.

Code:
Sub PrintSheet()
 
    Dim Cell As Range
 
    For Each Cell In Range("PlanList")
        X = Cell.Value
        Range("C9") = X
        ActiveWindow.SelectedSheets.PrintOut copies:=1
 
    Next Cell
 
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Does something like this work for you?

Code:
Sub Macro5()
    Dim WkSht As Worksheet, Cell As Range, X As Variant
    
    For Each Cell In Range("PlanList")
        
        'Sets new value
        X = Cell.Value
        Sheets("Sheet1").Range("C9") = X
        
        'Creates new workbook with selected sheets (still formula based though)
        ActiveWindow.SelectedSheets.Copy
        
        'Cycles through each sheet and creates a values only version of each
        For Each WkSht In ActiveWorkbook.Sheets
            WkSht.Cells.Copy
            WkSht.Cells.PasteSpecial Paste:=xlPasteValues
            Application.CutCopyMode = False
        Next WkSht
        
        'Saves and closes the workbook (Without this code, the activeworkbook
        'is still the newly created one, so I think the cycle would break when
        'it tries to set a new value to X again on the next time through)
        ActiveWorkbook.Save
        ActiveWorkbook.Close
    Next Cell
End Sub

Hope this helps,
~Gold fish
 
Upvote 0
yes that helped so much.

now what if i just want my print_area copied/pasted and not the whole worksheet?
 
Upvote 0
Is it only one sheet's print area you have to copy paste? if so you can use this:

Code:
Sub Macro6()
    Dim WkSheet As Worksheet, Cell As Range, X As Variant
    
    For Each Cell In Range("PlanList")
        
        'Sets new value
        X = Cell.Value
        Sheets("Sheet1").Range("C9") = X
        
        'Copy Print_area
        Range("Print_Area").Copy
        
        'Add a new sheet (and stores the name of the new sheet
        'into the WkSheet variable so we can reference it later)
        Set WkSheet = Sheets.Add
        
        'Paste the copied values into the new sheet
        WkSheet.Range("A1").PasteSpecial Paste:=xlPasteValues
        
        'Moves the new sheet to its own workbook
        WkSheet.Move
        
        ActiveWorkbook.Save
        ActiveWorkbook.Close
    Next Cell
End Sub
 
Upvote 0
i like what's occurring better in the first macro but if i could only paste my particular print area instead.
 
Upvote 0

Forum statistics

Threads
1,215,065
Messages
6,122,944
Members
449,095
Latest member
nmaske

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