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
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