volchara: (Default)
[personal profile] volchara
Мне нужно было синкить 2 екселовских файла, а самому лень. И чо вы думаете, таки чатжпт могЁт! Надо будет чутка поправить, но для начала уже ничего


create VBA script to sync 2 excel files by 1st column and adding additional columns and rows if missing in the 1st excel file from 2nd excel file

Sure! Here is an example VBA script that should accomplish what you described.

Assuming your first Excel file is called "ExcelFile1.xlsx" and has data in Sheet1, and your second Excel file is called "ExcelFile2.xlsx" and also has data in Sheet1.

This script will compare the first column of both sheets, and if a row exists in ExcelFile2.xlsx that does not exist in ExcelFile1.xlsx, it will add that row to ExcelFile1.xlsx and copy over any additional columns from ExcelFile2.xlsx.

VBA
Copy code

Sub SyncExcelFiles()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim i As Long
Dim j As Long
Dim lastrow1 As Long
Dim lastrow2 As Long
Dim foundMatch As Boolean

'Set up the two workbooks and worksheets
Set wb1 = Workbooks.Open("C:\Path\To\ExcelFile1.xlsx")
Set wb2 = Workbooks.Open("C:\Path\To\ExcelFile2.xlsx")
Set ws1 = wb1.Sheets("Sheet1")
Set ws2 = wb2.Sheets("Sheet1")

'Get the last row of data in each sheet
lastrow1 = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
lastrow2 = ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row

'Loop through each row in ExcelFile2.xlsx
For i = 1 To lastrow2
foundMatch = False
'Loop through each row in ExcelFile1.xlsx
For j = 1 To lastrow1
'If there is a match on the first column, copy over additional columns
If ws2.Cells(i, 1).Value = ws1.Cells(j, 1).Value Then
foundMatch = True
'Copy over additional columns from ExcelFile2.xlsx
ws1.Cells(j, 2).Value = ws2.Cells(i, 2).Value 'Change 2 to the column number you want to copy over
ws1.Cells(j, 3).Value = ws2.Cells(i, 3).Value 'Change 3 to the column number you want to copy over
'Add more lines for additional columns as needed
Exit For
End If
Next j
'If there is no match in ExcelFile1.xlsx, add the row from ExcelFile2.xlsx
If Not foundMatch Then
lastrow1 = lastrow1 + 1
ws1.Cells(lastrow1, 1).Value = ws2.Cells(i, 1).Value
ws1.Cells(lastrow1, 2).Value = ws2.Cells(i, 2).Value 'Change 2 to the column number you want to copy over
ws1.Cells(lastrow1, 3).Value = ws2.Cells(i, 3).Value 'Change 3 to the column number you want to copy over
'Add more lines for additional columns as needed
End If
Next i

'Save and close the workbooks
wb1.Save
wb1.Close
wb2.Close

'Cleanup
Set ws1 = Nothing
Set ws2 = Nothing
Set wb1 = Nothing
Set wb2 = Nothing
End Sub


You will need to customize the file paths in the code to match the location of your files, and also update the column numbers to match the additional

Date: 2023-02-23 05:05 am (UTC)
paserbyp: (Default)
From: [personal profile] paserbyp
Это только начало, а скоро codeGRT код сгенерирует на основании спецификации и ты можешь отправляться в безработные на пособие…
Edited Date: 2023-02-23 05:05 am (UTC)

Date: 2023-02-23 05:26 am (UTC)
paserbyp: (Default)
From: [personal profile] paserbyp
хто ты? В глаза смотреть!

Date: 2023-02-23 05:29 am (UTC)
paserbyp: (Default)
From: [personal profile] paserbyp
А под пытками?

Date: 2023-02-23 01:57 pm (UTC)
paserbyp: (Default)
From: [personal profile] paserbyp
Биткоин в сраку? Оригинально…

Date: 2023-02-23 05:19 am (UTC)
lxe: (Default)
From: [personal profile] lxe
Лицензия какая?

Date: 2023-02-23 05:31 am (UTC)
lxe: (Default)
From: [personal profile] lxe
На употребление кода, произведенного этой железякой. Там же есть какая-то? Ну, хотя бы disclaimer of warranty есть? (Я не утверждаю, что должны быть, но любопытно.)

Date: 2023-02-23 05:53 am (UTC)
lxe: (Default)
From: [personal profile] lxe
Одно другому не противоречит. Как показывает опыт винды, никое количество ошибок не мешает наличию лицензии.
Но спорить не буду, просто стало любопытно. По-моему, в среде корпоративной разработки ни одна собака не чихнет без ToS/EULA, странно, что тут этот момент пропущен.

Date: 2023-02-23 03:23 pm (UTC)
merig00: (Default)
From: [personal profile] merig00
Can I use output from ChatGPT for commercial uses?

Subject to the Content Policy and Terms, you own the output you create with ChatGPT, including the right to reprint, sell, and merchandise – regardless of whether output was generated through a free or paid plan.

https://help.openai.com/en/articles/6783457-chatgpt-general-faq#:~:text=Can%20I%20use%20output%20from,a%20free%20or%20paid%20plan.

Date: 2023-02-23 03:54 pm (UTC)
lxe: (Default)
From: [personal profile] lxe
Ага, оно!

Date: 2023-02-23 04:31 pm (UTC)
merig00: (Default)
From: [personal profile] merig00
Ну в зависимости что критично - если факты и конкретные данные то нет, если код то да т.к. он или работает или нет и то же самое с текстом например образец контракта написать или письмо какое-то то тоже да т.к. фактов нет а просто бла бла стандартное.

Date: 2023-02-23 07:50 pm (UTC)
merig00: (Default)
From: [personal profile] merig00
Угу...

Я с ним только что попытался в Wordle сыграть. По идее самое то для него. Фиг тебе. Считает что в слове HOUSE буква U на 5ой позиции. В слове TRUCE буква E на второй позиции. В слове THEME присутствует буква U. Предлагал слова из 4 букв хотя надо пять. и т.д. Даже умудрился один раз поспорить что он все правильно сказал

I apologize for the mistake in my previous statement. The correct positions of the letters in the word "HOUSE" are:

The letter "H" is in the first position.
The letter "O" is in the second position.
The letter "U" is in the fourth position.
The letter "S" is in the third position.
The letter "E" is in the fifth position.
I hope that clears up any confusion. Please let me know if you have any further questions!

Пичалька

Date: 2023-02-23 05:22 am (UTC)
alexanderr: (Default)
From: [personal profile] alexanderr
не, норм конечно, но он может и посерьезнее код. а еще народ его использует как debugger. ну вместе смотреть на код и искать ошибку или просто слабые места

Date: 2023-02-23 01:58 pm (UTC)
sobriquet9: (Default)
From: [personal profile] sobriquet9
А ничего, что два вложенных цикла и поэтому асимптотическая сложность O(N2)?

Date: 2023-02-23 04:01 pm (UTC)
sobriquet9: (Default)
From: [personal profile] sobriquet9
В поставленном условии ничего нет про сотню записей.

Date: 2023-02-23 05:15 pm (UTC)
From: [personal profile] xwind

https://support.microsoft.com/en-us/office/import-data-from-data-sources-power-query-be4330b3-5356-486c-a168-b68e9e616f5a

Короче изучай новые технологии, и закопай наконец стюардессу :)

Date: 2023-02-23 05:35 pm (UTC)
From: [personal profile] xwind

Если у тебя 100 строк и там и там, то там даже васик не нужон, ^A ^C ^V, Data > Data Tools > Remove Duplicates, Save.

Edited Date: 2023-02-23 05:46 pm (UTC)

Date: 2023-02-23 08:02 pm (UTC)
sobriquet9: (Default)
From: [personal profile] sobriquet9
Тогда не надо было требовать VBScript. За пять минут это делается без программирования, с использованием формулы VLOOKUP() или комбинации INDEX() и MATCH().

Profile

volchara: (Default)
V. O'Hara

April 2024

S M T W T F S
 123456
78910111213
1415 1617 181920
21222324252627
282930    

Links

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 8th, 2026 10:28 am
Powered by Dreamwidth Studios