Failure vba code

SimbadS

New Member
Joined
Feb 13, 2020
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have this code that fails and gives med errorcode "1004" and stops at ".value = .Value"
Point is to make a copy of open sheets to a new workbook whitout formulas and just numbers.

Here is the code:
VBA Code:
Sub New_workbook()
   Dim Ary As Variant
   Dim Ws As Worksheet
   Dim i As Long
   
   ReDim Ary(1 To Worksheets.Count)
   Sheets("Hidden_sheet").Visible = True
   For Each Ws In Worksheets
   
      If Ws.Visible = xlSheetVisible Then
   
         Select Case Ws.Name
         
            Case "Start_sheet"
            Case Else
               i = i + 1
               Ary(i) = Ws.Name
         End Select
         
      End If
      
   Next Ws
  Sheets("Hidden_sheet").Visible = False
  
   ReDim Preserve Ary(1 To i)
   Application.Calculation = xlManual
   
   Sheets(Ary).Copy
   For Each Ws In Worksheets
      With Ws.UsedRange
         .Value = .Value
      End With
  Sheets("Hidden_sheet").Visible = True
   Next Ws
   
   Application.Calculation = xlAutomatic

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hello Sinbad'S,
if you still not resolved error I have create new piece of code for you.

VBA Code:
Sub CopyVisibleSheets()
        
        Dim varWorksheet As Worksheet
        Dim varNLoops As Integer
        Dim varActiveWorkbook, varNewWorkbook As Workbook
        Dim varSheetName As String
        
        Application.ScreenUpdating = False
        
        Set varActiveWorkbook = ActiveWorkbook
        Workbooks.Add
        Set varNewWorkbook = ActiveWorkbook
        
        Application.DisplayAlerts = False
        Sheets(2).Delete
        Sheets(2).Delete
        
        varActiveWorkbook.Activate
        For Each varWorksheet In Worksheets
                If varWorksheet.Visible = xlSheetVisible Then
                        varWorksheet.Activate
                        varSheetName = ActiveSheet.Name
                        varWorksheet.UsedRange.Copy
                        varNewWorkbook.Activate
                        ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues
                        Application.CutCopyMode = False
                        ActiveSheet.Name = varSheetName
                        varNewWorkbook.Sheets.Add
                        varActiveWorkbook.Activate
                End If
        Next varWorksheet
        
        varNewWorkbook.Activate
        ActiveSheet.Delete
        Range("A1").Select
        
        Application.ScreenUpdating = True
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,379
Messages
6,119,190
Members
448,874
Latest member
Lancelots

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