Copy Each Cell in Range on one worksheet to cell in another worksheet data updates save copy of workbook repeat through first range

mjb342

New Member
Joined
May 3, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a range of "Id's" in one worksheet (A4:A18) that I'd like to loop through and copy each and paste the values into cell G4 of another worksheet. The cells on that worksheet would then update based on the new ID. From there I want to save a copy of the workbook that will include that ID and the cell above it which is a name. Super new but eager to keep learning.


VBA Code:
Sub Save_Copy_File()
Dim ID As Range
Dim srcWS As Worksheet
Dim LastRow As Long
Dim Filename As String
Dim Path As String


Application.ScreenUpdating = False
Path = "\\this is where i want the file saved"
Set Filename = Worksheets("TP").Range("G3").Value
Set srcWS = Sheets("TD")
LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For Each ID In srcWS.Range("A4:A18")
Sheets("TD").Range("A4").Copy
Sheets("TP").Range("G4").PasteSpecial Paste:=xlPasteValues
ActiveWorkbook.SaveCopyAs Filename:=Path & ID & "_" & Filename & "_4.30.20 FYE Pro" & ".xlsm"
Next ID
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
How about

VBA Code:
Sub Save_Copy_File()
  Dim c As Range, sPath As String, sName As String
  Application.ScreenUpdating = False
  '
  sPath = "C:\trabajo\"
  sName = Worksheets("TP").Range("G3").Value
  '
  For Each c In Sheets("TD").Range("A4:A18")
    Sheets("TP").Range("G4").Value = c.Value
    ActiveWorkbook.SaveCopyAs Filename:=sPath & c.Value & "_" & sName & "_4.30.20 FYE Pro" & ".xlsm"
  Next c
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
That worked well. Only remaining issue is that it's saving each file as the name of the first file. In other words G3 gets updated in the file when G4 changes it's just that the filename doesn't pick that up. The ID changes for each workbook that's saved.
 
Upvote 0
Try this

VBA Code:
Sub Save_Copy_File()
  Dim c As Range, sPath As String, sName As String
  Application.ScreenUpdating = False
  '
  sPath = "C:\trabajo\"
   For Each c In Sheets("TD").Range("A4:A18")
    Sheets("TP").Range("G4").Value = c.Value
    sName = Sheets("TP").Range("G3").Value 
   ActiveWorkbook.SaveCopyAs Filename:=sPath & c.Value & "_" & sName & "_4.30.20 FYE Pro" & ".xlsm"
  Next c
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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