copy from wb1 to wb1 and allow for other entries

BebeM

New Member
Joined
Sep 29, 2022
Messages
19
Office Version
  1. 365
  2. 2021
  3. 2013
Platform
  1. Windows
Greeting to all

I would appreciate your help on creating the code where as it appears on the image, i just need the highlighted data on workbook1 to populate on workbook2, sheet "File summary) and to allow other more entries going down.

As always, your help is highly appreciated.

LadyB
 

Attachments

  • FILE SUMM.png
    FILE SUMM.png
    61 KB · Views: 5

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
What is the name of each of these workbooks?
Will they both already be open at the time when you will be running this code?
What is the name of the sheet where the data is coming from?
 
Upvote 0
Assuming both files are already open, and the VBA code is to be stored in the sheet where the entries are being made originally, you could use some code like this:
VBA Code:
Sub MyCopyData()

    Dim wb1 As Workbook, wb2 As Workbook
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim nr As Long
    Dim n As String, g As String, r As String
        
'   Set workbook variables
    Set wb1 = ThisWorkbook
    Set wb2 = Workbooks("Book11.xlsm")

'   Set worksheet variables
    Set ws1 = wb1.Sheets("Sheet1")
    Set ws2 = wb2.Sheets("FILE SUMMARY")
    
'   Get values to populate
    n = ws1.Range("B3")
    g = ws1.Range("B10")
    r = ws1.Range("B12")
    
'   Find next available row in column A of FILE SUMMARY sheet
    wb2.Activate
    nr = ws2.Cells(ws2.Rows.Count, "A").End(xlUp).Row + 1
    
'   Populate new row with values
    ws2.Cells(nr, "A").Value = n
    ws2.Cells(nr, "B").Value = g
    ws2.Cells(nr, "C").Value = r

End Sub

You would just need to update this part:
Rich (BB code):
    Set wb2 = Workbooks("Book11.xlsm")
to reflect the name of your workbook with the "FILE SUMMARY" tab

and you would need to update this part:
Rich (BB code):
    Set ws1 = wb1.Sheets("Sheet1")
to reflect the name of the sheet where your entry grid resides.
 
Upvote 0
Thank you Joe, truly appreciate your assistance.

I have placed the code as below, but i get (Run-time error 9, Subscript out of range. What could i be doing wrong
to answer your first questions:

What is the name of each of these workbooks? wb1 is LDS and wb2 is Reporting
Will they both already be open at the time when you will be running this code? only wb1 will be open and Reporting will be closed and my colleagues cannot access it but only me and my senior
What is the name of the sheet where the data is coming from? data will be coming from wb1 which is LDS

Private Sub CommandButton4_Click()

Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim nr As Long

Dim n As String, g As String, r As String

' Set workbook variables
Set wb1 = ThisWorkbook
Set wb2 = Workbooks("REPORTING.xlsm")

' Set worksheet variables
Set ws1 = wb1.Sheets("MATTER DETAILS")
Set ws2 = wb2.Sheets("FILE SUMMARY")

' Get values to populate
n = ws1.Range("B3")
g = ws1.Range("B10")
r = ws1.Range("B12")

' Find next available row in column A of FILE SUMMARY sheet
wb2.Activate
nr = ws2.Cells(ws2.Rows.Count, "A").End(xlUp).Row + 1

' Populate new row with values
ws2.Cells(nr, "A").Value = n
ws2.Cells(nr, "B").Value = g
ws2.Cells(nr, "C").Value = r

MsgBox "You have successfully transferred your entry onto LDS", vbInformation,

End Sub
 
Upvote 0
Will they both already be open at the time when you will be running this code? only wb1 will be open and Reporting will be closed and my colleagues cannot access it but only me and my senior
Then it makes sense that the code is returning errors, as only one workbook is open!
You will need to add code to this to first open the other workbook.

That will look something like this:
Rich (BB code):
Private Sub CommandButton4_Click()

Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim nr As Long

Dim n As String, g As String, r As String

' Set workbook variables
Set wb1 = ThisWorkbook

' Open REPORTING workbook
Workbooks.Open Filename:="put file path and name here"
Set wb2 = ActiveWorkbook

' Set worksheet variables
Set ws1 = wb1.Sheets("MATTER DETAILS")
Set ws2 = wb2.Sheets("FILE SUMMARY")

' Get values to populate
n = ws1.Range("B3")
g = ws1.Range("B10")
r = ws1.Range("B12")

' Find next available row in column A of FILE SUMMARY sheet
wb2.Activate
nr = ws2.Cells(ws2.Rows.Count, "A").End(xlUp).Row + 1

' Populate new row with values
ws2.Cells(nr, "A").Value = n
ws2.Cells(nr, "B").Value = g
ws2.Cells(nr, "C").Value = r

MsgBox "You have successfully transferred your entry onto LDS", vbInformation

End Sub
Note that you will need to replace "put file path and name here" with the full path and file name (including extension) of your REPORTING file.
 
Upvote 1
Solution
You are welcome.
Glad I was able to help!

Note: When marking posts as a solution, please be sure to mark the post that actually contains the solution, not your own post acknowledging that some other post is the solution.
I have updated this thread for you.
 
Upvote 0

Forum statistics

Threads
1,215,583
Messages
6,125,661
Members
449,247
Latest member
wingedshoes

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