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.
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Header 1[/TD]
[TD]Header 2[/TD]
[TD]Header 3[/TD]
[TD]Header 4[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD][/TD]
[TD]050[/TD]
[TD]Ignore[/TD]
[/TR]
[TR]
[TD]Jill[/TD]
[TD][/TD]
[TD]100[/TD]
[TD]Don't Ignore[/TD]
[/TR]
[TR]
[TD]Jack[/TD]
[TD][/TD]
[TD][/TD]
[TD]Talk to[/TD]
[/TR]
[TR]
[TD]Joe[/TD]
[TD][/TD]
[TD]050[/TD]
[TD]Ignore[/TD]
[/TR]
</tbody>[/TABLE]
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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
=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.

[TABLE="class: cms_table_grid, width: 500"]
<tbody>[TR]
[TD]Header 1[/TD]
[TD]Header 2[/TD]
[TD]Header 3[/TD]
[TD]Header 4[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD][/TD]
[TD]050[/TD]
[TD]Ignore[/TD]
[/TR]
[TR]
[TD]Jill[/TD]
[TD][/TD]
[TD]100[/TD]
[TD]Don't Ignore[/TD]
[/TR]
[TR]
[TD]Jack[/TD]
[TD][/TD]
[TD][/TD]
[TD]Talk to[/TD]
[/TR]
[TR]
[TD]Joe[/TD]
[TD][/TD]
[TD]050[/TD]
[TD]Ignore[/TD]
[/TR]
</tbody>[/TABLE]

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,224,942
Messages
6,181,903
Members
453,070
Latest member
sivasj

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