VBA - copy specific cells with criteria to multiple workbooks (get filename from cells)

keresztesi

Board Regular
Joined
Aug 14, 2017
Messages
64
Hi,

I need your help.
Here is a sample table.

So I need the following:

1. IF ColE and ColF are not blank and ColG is blank then
2. Copy the values from ColE and ColF to another workbook
3. ColH contains the workbook name (path will be always the same)
4. It should copy these values to the given workbook, given worksheet column number 8 and 9
5. For row number it should search for "AZON" in colA which is identical in source and destination workbooks ("AZON" is always in ColA)
6. After copy was succesfull it should write an "x" to ColG in the sourcesheet

ABCDEFGHI
1AZONTerületProbléma leírásaKategóriaFelelősHatáridőVisszaküldvefileKÉSZ
2terület1_1CORAZZAsfgfsgfgSebességet befolyásolóJohn Doe2018.08.31
terület1
3terület1_2REXsfgvsfgfMunkabiztonságterület1
4terület3_1TZR1ethbetAkutterület3
5terület4_1CORAZZAaaaaPreventívPaula Abdul2018.09.10xterület4

<tbody>
</tbody>

So, in that example the code should copy values "John Doe" and "2018.08.31" to the workbook "terület1". Row number is where "terület1_1" is in workbook "terület1", the values go to row numbers 8 and 9. After that it writes an "x" to column G.

Thank you in advance!

Zoli
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I have a similar vba, but in that case I don't need to copy data to different workbooks.
Is it a help for somebody to rewrite it?

Sub exportData()


Dim LastRow As Integer
Dim i As Integer
Dim erow As Integer
Dim wbk As Workbook
Dim SourceSheet As Worksheet
Dim DestSheet As Worksheet
Dim Sorszám, AZON, Terület, Probléma_leírása, Kategória, File


Set SourceSheet = ThisWorkbook.Sheets("terület1")
LastRow = SourceSheet.Range("A" & Rows.Count).End(xlUp).Row
Set wbk = Workbooks.Open(ThisWorkbook.Path & "\TMK.xlsm")
Set DestSheet = wbk.Sheets("Munka1")


For i = 2 To LastRow
If SourceSheet.Cells(i, 7).Value = "" And SourceSheet.Cells(i, 1) <> "" Then
'change the column numbers to the relevant number
AZON = SourceSheet.Cells(i, 1).Value
Terület = SourceSheet.Cells(i, 4).Value
Probléma_leírása = SourceSheet.Cells(i, 5).Value
Kategória = SourceSheet.Cells(i, 6).Value
File = SourceSheet.Cells(i, 2).Value

SourceSheet.Cells(i, 7) = "x"

erow = DestSheet.Cells(DestSheet.Rows.Count, 1).End(xlUp).Offset(1, 0).Row


'change the column numbers to the relevant number
DestSheet.Cells(erow, 1).Value = AZON
DestSheet.Cells(erow, 2).Value = Terület
DestSheet.Cells(erow, 3).Value = Probléma_leírása
DestSheet.Cells(erow, 4).Value = Kategória
DestSheet.Cells(erow, 8).Value = File
End If
Next i



wbk.Save
'wbk.Close
End Sub


Thx
Zoli
 
Upvote 0
I have this above:
Set wbk = Workbooks.Open(ThisWorkbook.Path & "\TMK.xlsm")

How can I change it not to use "TMK.xlsm" but use always the proper filename from cell values from row.

Thx
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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