Macro to read text in cell and write in adjacent cell

shre0047

Board Regular
Joined
Feb 3, 2017
Messages
53
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I'm trying to come up with a macro where for a specific column, depending on what each cell value is, the adjacent value is provide a certain value.
Header 1Header 2Header 3Header 4
John050Ignore
Jill100Don't Ignore
JackTalk to
Joe050Ignore

<tbody>
</tbody>
For example, in cell D2, I have the value set as "Ignore." The macro would look at this cell, determine it is value of "Ignore" then write in cell C2, 050.
Additionally, in cell D4, the value is set as "Talk to." So the value of C4 will be blank (if there was a previous value, it would be removed)
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
=IF(D2="Ignore","050",IF(D2="Don't Ignore","100",""))

Assuming that you don't have any other values other than those 3 in column-D.

Put that in C2 and copy down.
 
Upvote 0
=IF(D2="Ignore","050",IF(D2="Don't Ignore","100",""))

Assuming that you don't have any other values other than those 3 in column-D.

Put that in C2 and copy down.

End users are going to be able to alter column C to different values (more than 3), so I was hoping to avoid using formulas.
 
Upvote 0
Hi,

here's the basic code to make a start.

Code:
Sub Action_add()

 Set rng = Range(Range("D2"), Range("D" & Rows.Count).End(xlUp))
  
   For Each cell In rng
    
    Select Case cell.Value
    
    Case "Ignore"
    
    cell.Offset(0, -1).Value = 50
    
    Case "Don't Ignore"
    
    cell.Offset(0, -1).Value = 100
    
    Case "Talk to"
    
    cell.Offset(0, -1).Value = ""
    
    Case Else
    
    End Select
   
Next
End Sub
 
Upvote 0
Thank you! This was a great start to the macro. I tweaked a few things to make it work for me.

Hi,

here's the basic code to make a start.

Code:
Sub Action_add()

 Set rng = Range(Range("D2"), Range("D" & Rows.Count).End(xlUp))
  
   For Each cell In rng
    
    Select Case cell.Value
    
    Case "Ignore"
    
    cell.Offset(0, -1).Value = 50
    
    Case "Don't Ignore"
    
    cell.Offset(0, -1).Value = 100
    
    Case "Talk to"
    
    cell.Offset(0, -1).Value = ""
    
    Case Else
    
    End Select
   
Next
End Sub
 
Upvote 0
I removed the line item regarding set 'Talk to' cell values as "" because if the cell was already entered by an end user, I don't want to lose that information.

Header 1Header 2Header 3Header 4
John050Ignore
Jill100Don't Ignore
JackTalk to
Joe050Ignore

<tbody>
</tbody>

What aspect do I need to include so that if D2 eventually changes from Ignore to Talk to, the 050 changes to blank?
 
Upvote 0
Hi,

It was explained that the entries in column 4 would determine the values in column 3 and that if 'Talk to' was encountered the adjacent cell would have any value removed.
So the macro employed just goes down column 4 and the content of column 4 determines what is in column 3.

So now you keep the user entered value against the Talk to and you want to change 050 to blank if it changes in future from Ignore to Talk to.

Can you potentially have an 050 with Ignore and an 050 with Talk to at any point in time? If not the code below may work but I suspect it may become more convoluted.
My other question is why, if you are editing the Ignore to Talk to, you can't manually clear the cell right next to the one you are editing?





Code:
    Case "Talk to"
    
    If Cell.Offset(0, -1).Value = "050" Then
       Cell.Offset(0, -1).Value = ""
       Else
       End If
    
    Case Else
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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