Is it possible to have a vba code that can add information from an open workbooks active…
- User
Is it possible to have a vba code that can add information from an open workbooks active sheet into a sheet of another workbook that is not open
- Assistant
Yes, it is possible to have a VBA code that can add information from an open workbook's active sheet into a sheet of another workbook that is not open. Here is an example VBA code:
Sub CopyDataToAnotherWorkbook() Dim sourceWB As Workbook Dim targetWB As Workbook Dim lastRow As Long
'Open the source workbook and set the active sheet Set sourceWB = ActiveWorkbook Set sourceWS = ActiveSheet
'Open the target workbook and set the target sheet Set targetWB = Workbooks.Open("path\to\target\workbook.xlsx") Set targetWS = targetWB.Sheets("Sheet1")
'Find the last row in the target worksheet lastRow = targetWS.Range("A" & Rows.Count).End(xlUp).Row + 1
'Copy the data from the source to the target sheet sourceWS.Range("A1:D10").Copy targetWS.Range("A" & lastRow)
'Close the target workbook targetWB.Close SaveChanges:=True
End Sub
In this code, we first set the source workbook and active sheet, and then set the target workbook and target sheet. We find the last row in the target worksheet and then copy the data from the source sheet to the target sheet. Finally, we close the target workbook. Note that you will need to replace "path\to\target\workbook.xlsx" with the actual file path of the target workbook.
- User
How can I modify this code so that from the opened workbooks active sheet, it writes values to a closed workbook named "TASK FOR TODAY AA" in the sheet named 'Tomorrow' starting from row 2 of column A
- Assistant
Here's the modified VBA code that writes values from an open workbook's active sheet to column A of a closed workbook named "TASK FOR TODAY AA" in the sheet named "Tomorrow" starting from row 2:
code - User
Please modify the code so that the values taken from the opened workbooks active sheet are between row A2 and row A21 only. The closed workbook path is G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\PREMISES STAFF SCHEDULES\TTASK FOR TODAY AA.xlsm
- Assistant
Here's the modified VBA code that writes values from an open workbook's active sheet to column A of a closed workbook named "TASK FOR TODAY AA.xlsm" in the sheet named "Tomorrow" starting from row 2 and ending at row 21:
code - User
The values taken from the source sheet have to be between A2 and A21
- Assistant
Apologies for the confusion earlier. Here's the modified VBA code that writes values from an open workbook's active sheet to column A of a closed workbook named "TASK FOR TODAY AA.xlsm" in the sheet named "Tomorrow" starting from row 2 and ending at row 21:
code