IF function comparing values from two columns

ChanL

Board Regular
Joined
Apr 8, 2021
Messages
65
Office Version
  1. 2019
Platform
  1. Windows
Currently, i have a table with multiple columns. And I want to compare the values in columns name "beneficiary name" and "sender name" using IF function
And i want to do this until the very last row of the available data

the expected outcome is :
If the value in beneficiary name = value in sender name , then it will return value as "own" else it will return as "third party"

P/s : I have alrdy create a VBA to automatically add a column name "type" at the right of the table
And now i wan the value for the IF function show in this column.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
P/s : I have alrdy create a VBA to automatically add a column name "type" at the right of the table
And now i wan the value for the IF function show in this column.
Perhaps you could share that code so we don't have to guess what tables are called, where things are etc and can make a fairly simple addition to your existing code?
 
Upvote 0
Perhaps you could share that code so we don't have to guess what tables are called, where things are etc and can make a fairly simple addition to your existing code?
Sure, this is so far what i have right now. Didn't manage to came out the code for the IF function as I really have no idea how to do it. So sorry

VBA Code:
Dim source as range, ws as worksheet

Set source = Range("A1").Currentregion
Set ws = Thisworkbook.sheets("Source")
ws.listobjects.add(SourceType:=xlsrcrange, source:=source, _
xllistobjecthasheaders:=xlyes, tablestylename:="TableStyleMedium27").Name="Table 1"

With ws.ListObjects ("Table 1")
.ListColumns.Add.Name = "Type"
End with

End sub
 
Upvote 0
Try this code with a copy of your workbook.

VBA Code:
Sub test()
  Dim rsource As Range, ws As Worksheet
  
  Set rsource = Range("A1").CurrentRegion
  Set ws = ThisWorkbook.Sheets("Source")
  ws.ListObjects.Add(SourceType:=xlSrcRange, source:=rsource, _
    xllistobjecthasheaders:=xlYes, tablestylename:="TableStyleMedium27").Name = "Table_1"
  
  With ws.ListObjects("Table_1")
    .ListColumns.Add.Name = "Type"
    .DataBodyRange(.Range.Columns.Count).Formula = "=IF([@[beneficiary name]]=[@[sender name]],""own"",""third party"")"
  End With
End Sub
 
Upvote 0
Try this code with a copy of your workbook.

VBA Code:
Sub test()
  Dim rsource As Range, ws As Worksheet
 
  Set rsource = Range("A1").CurrentRegion
  Set ws = ThisWorkbook.Sheets("Source")
  ws.ListObjects.Add(SourceType:=xlSrcRange, source:=rsource, _
    xllistobjecthasheaders:=xlYes, tablestylename:="TableStyleMedium27").Name = "Table_1"
 
  With ws.ListObjects("Table_1")
    .ListColumns.Add.Name = "Type"
    .DataBodyRange(.Range.Columns.Count).Formula = "=IF([@[beneficiary name]]=[@[sender name]],""own"",""third party"")"
  End With
End Sub
Hi peter! Thanks so much for the help, this works perfectly fine. But just a quick question . the code .DataBodyRange(.Range.Columns.Count).Formula = , is it possible for me to use it with diff excel formula besides the IF functions?
 
Upvote 0
Sure, you could any formula you want in the column.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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