Paste Value based upon different conditions

lostballtallweeds

New Member
Joined
Sep 26, 2017
Messages
3
My spreadsheet is set up this way, with 50+ rows following the same pattern.

[TABLE="width: 500"]
<tbody>[TR]
[TD]ID#[/TD]
[TD]TEAM[/TD]
[TD]TEAMLEADER[/TD]
[TD]TEAMMEMBER[/TD]
[TD]PHONE#[/TD]
[TD]COMMENT[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]BLUE[/TD]
[TD]HAROLD[/TD]
[TD]MARTHA[/TD]
[TD]555-5555[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]RED[/TD]
[TD]BILL[/TD]
[TD]TONY[/TD]
[TD]555-5556[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]GREEN[/TD]
[TD]HAROLD[/TD]
[TD]CYNTHIA[/TD]
[TD]555-5557[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]



I want to set up several Macros and corresponding buttons to insert a text string in the "Comment" column. For example, I want a button to insert
"No. Harold" in the "Comment" column in each row where Harold is the TeamLeader. I also want a button that will enter "Yes. Harold" in each row where Harold is the TeamLeader. I would like the same macros for Bill.


If possible, i'd also like macros that insert different text strings based upon the "Team" text.

The comment column won't be populated simultaneously or I think I could find a work-around.


Is there any good way to do this? I think if i could get one macro set up, I could adapt it to any criteria.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hello,

I would use one template and copy it for each of your different buttons that you want to set up. Here is the template I would use (where you would update the three variables listed):

Code:
Sub lostballtallweeds()
Dim lrow As Long
Dim VariableName As String
Dim VariableColumn As Integer
Dim Output As String
Dim i As Long

'Update the three variables below for how you would like the button to work
VariableName = "HAROLD"
VariableColumn = 3
Output = "No. HAROLD"


lrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lrow
    If Cells(i, VariableColumn) = VariableName Then Cells(i, 6) = Output
Next i

End Sub


Example 1: No. Harold
Code:
Sub NoHarold()
Dim lrow As Long
Dim VariableName As String
Dim VariableColumn As Integer
Dim Output As String
Dim i As Long

'Update the three variables below for how you would like the button to work
VariableName = "HAROLD"
VariableColumn = 3
Output = "No. HAROLD"


lrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lrow
    If Cells(i, VariableColumn) = VariableName Then Cells(i, 6) = Output
Next i

End Sub

Example 2 Yes. Bill:
Code:
Sub YesBill()
Dim lrow As Long
Dim VariableName As String
Dim VariableColumn As Integer
Dim Output As String
Dim i As Long

'Update the three variables below for how you would like the button to work
VariableName = "BILL"
VariableColumn = 3
Output = "Yes. BILL"


lrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lrow
    If Cells(i, VariableColumn) = VariableName Then Cells(i, 6) = Output
Next i

End Sub

Example 3 No. Blue
Code:
Sub lostballtallweeds()
Dim lrow As Long
Dim VariableName As String
Dim VariableColumn As Integer
Dim Output As String
Dim i As Long

'Update the three variables below for how you would like the button to work
VariableName = "BLUE"
VariableColumn = 2
Output = "No. BLUE"


lrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lrow
    If Cells(i, VariableColumn) = VariableName Then Cells(i, 6) = Output
Next i

End Sub

Notice how in example 3 I had to change the column number to represent the column that your team names lived in.

Let me know if you have any questions!

Sincerely,
Max
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,757
Messages
6,174,331
Members
452,555
Latest member
colc007

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