VBA help

Giggzz

Well-known Member
Joined
Jul 4, 2002
Messages
990
Code:
Private Sub CommandButton1_Click()
ActiveSheet.Unprotect "national"
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
With Range("V:V")
.EntireColumn.ClearContents
Dim FilterRange As Range, PrintRange As Range
Set FilterRange = Range(("A4"), cells(Rows.Count, 1).End(xlUp).Offset(0, 22))
Set PrintRange = Range(("A1"), cells(Rows.Count, 1).End(xlUp).Offset(0, 20))
Range(("V4:V63"), cells(Rows.Count, 1).End(xlUp).Offset(0, 22)).Formula = "=IF(SUM(RC2,RC6,RC10,RC14)>0,""Yes"",""No"")"
Range("V4,V62:V64") = "Yes"
.Value = .Value
FilterRange.AutoFilter Field:=22, Criteria1:="Yes"
PrintRange.PrintOut
ActiveSheet.AutoFilterMode = False
.EntireColumn.ClearContents
End With
Set FilterRange = Nothing
Set PrintRange = Range(("A63"), cells(Rows.Count, 1).End(xlUp).Offset(0, 21))
Application.ScreenUpdating = True
ActiveSheet.Protect "national"
End Sub
THe above code prints only the information I need, but what Im looking to do is have the information copied to a blank worksheet. What mod would have to be done to have this happen?
 
Last edited by a moderator:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
Giggzz

I'll take a look at your code tomorrow, it's late here.:)

But one thing you could try doing is using code tags.

It makes it easier to follow/understand the code and will increase the chances of you getting help.:)
 
Upvote 0

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
Maybe something like this -- call this subroutine with your PrintRange instead of MyRange as in the example:

Code:
Sub testit()
Dim MyRange As Range

    Set MyRange = Range("A1:A10")
    Call ExportToWorksheet(MyRange, ActiveSheet)

End Sub
'-------------------------------------------------
Private Sub ExportToWorksheet(ByRef Arg1 As Range, wsCopiedFromWorkSheet As Worksheet)
Dim ws As Worksheet
    
    Arg1.Copy
    Set ws = Workbooks.Add.Worksheets(1)
    ws.Cells(1, 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
    Application.CutCopyMode = False

    wsCopiedFromWorkSheet.Activate

End Sub

There must be alternative solutions, I am sure... I've taken the precaution of activating the original worksheet so that your remaining code will continue to work on the assumption that that is still the activesheet.

HTH
 
Last edited:
Upvote 0

Forum statistics

Threads
1,191,118
Messages
5,984,749
Members
439,907
Latest member
Kayfabe

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
Top