Need help with VBA Code in Copying multiple sheets to a new a workbook

aashish83

Board Regular
Joined
Feb 15, 2022
Messages
62
Office Version
  1. 365
Platform
  1. Windows
I have the following code i just want that when copying "BI" sheet it should just copy from Range A1:C28 and the rest to remain as it is....Below is the code

Sub FSRA()

With ActiveWorkbook.Sheets(Array("FSR Level A", "BI", "Instructions"))
.Copy
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & "Audit Form FSR A", FileFormat:=52

End With

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Does this do what you want...

VBA Code:
Sub FSRA()
    
    Dim rng As Range
    With ActiveWorkbook.Sheets(Array("FSR Level A", "BI", "Instructions"))
        Set rng = ActiveWorkbook.Worksheets("BI").Range("A1:C28")
        .Copy
        ActiveWorkbook.Worksheets("BI").Cells.ClearContents
        ActiveWorkbook.Worksheets("BI").Range("A1:C28") = rng.Value2
        ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & "Audit Form FSR A", FileFormat:=52
    End With

End Sub
 
Upvote 0
Does this do what you want...

VBA Code:
Sub FSRA()
   
    Dim rng As Range
    With ActiveWorkbook.Sheets(Array("FSR Level A", "BI", "Instructions"))
        Set rng = ActiveWorkbook.Worksheets("BI").Range("A1:C28")
        .Copy
        ActiveWorkbook.Worksheets("BI").Cells.ClearContents
        ActiveWorkbook.Worksheets("BI").Range("A1:C28") = rng.Value2
        ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & "Audit Form FSR A", FileFormat:=52
    End With

End Sub

Hi
This removes all content in A1:C28 in the new sheet and it is still copying A29...Is it possible that we can just hide A29, A30 & 31 in new sheet automatically?
 
Upvote 0
Did you actually try the code... On my test sheet, the code completely cleared Sheet BI and copied the Range("A1:C28") back into that sheet as per your Post #1.
 
Upvote 0
Did you actually try the code... On my test sheet, the code completely cleared Sheet BI and copied the Range("A1:C28) back into that sheet as per your Post #1.
Yes i did try it and i don't want it clear the data i just want to only copy (A1:C28) and not beyond that from BI sheet
 
Upvote 0
I don't understand, you only want Range(A1:C28) on sheet BI from the source workbook copied to the new workbook. This clears the Sheet BI in the new workbook and copies just that range to it.
 
Upvote 0
I don't understand, you only want Range(A1:C28) on sheet BI from the source workbook copied to the new workbook. This clears the Sheet BI in the new workbook and copies just that range to it.
Then BI sheet in new workbook is blank so i guess we don't need to clear contents
 
Upvote 0
If you don't clear contents you are back to where you were with your original code...
 
Upvote 0
The below code did the trick for me, changed the range from the original code.

Sub FSRA()

Dim rng As Range
With ActiveWorkbook.Sheets(Array("FSR Level A", "BI", "Instructions"))
Set rng = ActiveWorkbook.Worksheets("BI").Range("A1:B28")
.Copy
ActiveWorkbook.Worksheets("BI").Range("B29:B31").EntireRow.Hidden = True
ActiveWorkbook.Worksheets("BI").Range("A1:B28") = rng.Value2
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & "Audit Form FSR A", FileFormat:=52
End With

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,487
Messages
6,125,086
Members
449,206
Latest member
ralemanygarcia

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