Create Specific Text down Column Based on Specific Text in Another Column

AlwaysLearning2018

Board Regular
Joined
Nov 23, 2018
Messages
51
Hi All,

I have created the below macro that will populate a value in 1 specific cell based on 1 specific cell in a different column. My question is how do I look at the entire column for that word and populate the other word down a different column Any help would be much appreciated!


Sub Comments()


If Worksheets(1).Range("D54").Value = "Variation Margin" Then
Worksheets(1).Range("I75").Value = "Futures Margin"

End If
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Last question . I have a few more different keywords in the same column that I need to generate different words in the other same column. How can I achieve that? I tried the same formula but just started new lines and changed the words but the macro only acted on the last set not the first in line.
 
Upvote 0
You can do it like
Code:
Sub AlwaysLearning2018()
   With Range("F2", Range("C" & Rows.Count).End(xlUp).Offset(, 3))
      .Value = Evaluate(Replace("If(@=""Variation Margin"",""Futures Margin""," & .Address & ")", "@", .Offset(, -3).Address))
      .Value = Evaluate(Replace("If(@=""Repo"",""Repo Margin""," & .Address & ")", "@", .Offset(, -3).Address))
   End With
End Sub
But this will insert a 0 in col F if col C does not match one of the Phrases.
 
Upvote 0
Try
Code:
Sub AlwaysLearning2018()
   With Range("F2", Range("C" & Rows.Count).End(xlUp).Offset(, 3))
      .Value = Evaluate(Replace("If(@=""Variation Margin"",""Futures Margin""," & .Address & ")", "@", .Offset(, -3).Address))
      .Value = Evaluate(Replace("If(@=""Repo"",""Repo Margin""," & .Address & ")", "@", .Offset(, -3).Address))
      .Value = Evaluate(Replace("If(@=0,"""",@)", "@", .Address))
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,712
Messages
6,174,031
Members
452,542
Latest member
Bricklin

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