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.

ID#TEAMTEAMLEADERTEAMMEMBERPHONE#COMMENT
1BLUEHAROLDMARTHA555-5555
2REDBILLTONY555-5556
3GREENHAROLDCYNTHIA555-5557

<tbody>
</tbody>



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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

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