Copy and Paste data from one workbook to another from specified cell

a_majda

New Member
Joined
May 18, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. Web
I have to prepare a macro for tickets. I have workbook (Test100). User open this workbook. If in column F in this workbook, user gonna change value (doen's matter what is the change, it can be just typping "x" inside the cell), macro should:
a) open new workbook (Test02) in specified location (always the same),
b) copy values from 2 cells in specified columns (A & B) from Test100 into FIRST BLANK row in specified columns (also A & B) in opened workbook - Test02
Test100 - from this I want to copy data
enter image description here
Test02 - here I want to paste the data
enter image description here
c) The point is to copy values from columns A & B but also from the ROW number in where somebody change the value in column F. Sometimes the mentioned values will be in row 3, another time in row 300 - but still in the same columns.
I wrote the code which works for points a) and b), but I have no idea what should I do with point c :( Could you help me?

Below you can find the code:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'Open new workbook (copy destination) after summoning it by change data in column F
If Not Intersect(Target, Range("F:F")) Is Nothing Then
Workbooks.Open "HERE IS THE DESTINATION OF DESTINATED WORKBOOK"

Dim wsCopy As Worksheet, wsDest As Worksheet
Dim ACopyLastRow As Long, ADestLastRow As Long, BCopyLastRow As Long, BDestLastRow As Long

'Set variables for copy and destination sheets
Set wsCopy = Workbooks("Test100").Worksheets("Arkusz1")
Set wsDest = Workbooks("Test02").Worksheets("Arkusz1")

'1. Find last used row in the copy range based on data in column A
ACopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, 1).End(xlUp).Row

'2. Find first blank row in the destination range based on data in column A
'Offset property moves down 1 row
ADestLastRow = wsDest.Cells(wsDest.Rows.Count, 4).End(xlUp).Offset(1, 0).Row

'3. Copy & Paste Data
wsCopy.Range("A" & ACopyLastRow).Copy _
wsDest.Range("A" & ADestLastRow)

'4. Find last used row in the copy range based on data in column B
BCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, 1).End(xlUp).Row

'5. Find first blank row in the destination range based on data in column B
'Offset property moves down 1 row
BDestLastRow = wsDest.Cells(wsDest.Rows.Count, 4).End(xlUp).Offset(1, 0).Row

'6. Copy & Paste Data
wsCopy.Range("B" & BCopyLastRow).Copy _
wsDest.Range("B" & BDestLastRow)


End If

End Sub
 

Attachments

  • 1652862750159.png
    1652862750159.png
    10.9 KB · Views: 11

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,224,812
Messages
6,181,088
Members
453,021
Latest member
Justyna P

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