copy data from other workbook with criteria

febrian91

New Member
Joined
Sep 17, 2014
Messages
10
Dear Master,

I wanna ask, how to copy data from another workbook with criteria. my criteria is copy the values in foreign currency exept for values in IDR currency. I have used "if" formula on my VBA formula, but it doesn't work. excel can not read my "if" formula, so excel just copy data without criteria. What's wrong with my formula? here is my formula:

Sub Format()
Dim wb1 As Workbook, wb2 As Workbook
Dim val As String
Dim i As Integer
Set wb1 = Workbooks("book1.xls")
Set wb2 = Workbooks("book2.xlsm")
val = wb2.Worksheets("sheet1").Range("m1").Value
Dim ws1 As Worksheet, ws2 As Worksheet
For Each ws1 In wb1.Worksheets
Set ws2 = wb2.Worksheets("sheet1")
If Cells(2, 14) <> val Then
wb1.Worksheets("sheet1").Range("a2:m17").Copy
wb2.Worksheets("sheet1").Range("a2:m17").PasteSpecial Paste:=xlPasteValues
End If
Next ws1

End Sub

Thank you Master
 

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.
Sir, i wanna ask. what's VBA formula should be used if i want to add fill colour "Red colour" for false condition and "Green colour" for true condition?
 
Upvote 0
Hello. Do you think if in excel, you use SQL language to copy, filter data and do dynamic reports? It is very easy if you use add-in a-tools. You can show your wordbook and i will try do it by add-in a-tools.
Thanks.

Thank you for your advice. How to do it? can you explain it?
 
Upvote 0

Forum statistics

Threads
1,224,900
Messages
6,181,634
Members
453,059
Latest member
jkevin

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