VBA to change color of cells information is being pasted into

jondavis1987

Active Member
Joined
Dec 31, 2015
Messages
443
Office Version
  1. 2019
Platform
  1. Windows
I have this vba for a command button. Cell D2 has a dropdown list that has the words "High", "Medium", "Low". The button will copy cells A2:C2 and paste the values in the last row. If D2 says High I'd like A2:C2 to be pasted into cells that are green, medium into yellow, and low into red. Any advice on how to alter this?

VBA Code:
Sub Log_Changes()

    Dim lastRow As Long
    Dim ws     As String
    Dim srcName As String
    Dim wsName As String
    ws = ActiveSheet.Name
    Application.DisplayAlerts = False
    
    lastRow = Sheets(ws).Cells(Rows.Count, "A").End(xlUp).Row + 1
    
    
    Sheets(ws).Range("A2:C2").Copy
    Sheets(ws).Range("A" & lastRow).PasteSpecial xlPasteValues

     
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Have you considered Conditional Formatting? This is a long video, but this channel has the best explanation of Conditional Formatting. If you want shorter videos, here's the Search of the channel's shorter videos.
 
Upvote 0
How is CF meant to copy/paste data?
 
Upvote 0
Have you considered Conditional Formatting? This is a long video, but this channel has the best explanation of Conditional Formatting. If you want shorter videos, here's the Search of the channel's shorter videos.
Can't really get conditional formatting to do what I need it to do.
 
Upvote 0
Figured it out

VBA Code:
Sub Log_Changes()

    Dim lastRow As Long
    Dim ws     As String

    wsName = ActiveSheet.Range("A1")
    ws = ActiveSheet.Name
    Application.DisplayAlerts = False

    
    lastRow = Sheets(ws).Cells(Rows.Count, "A").End(xlUp).Row + 1
    
    If Sheets(ws).Range("D5") = "HIGH" Then Sheets(ws).Range("A" & lastRow).Interior.Color = vbGreen
    If Sheets(ws).Range("D5") = "MEDIUM" Then Sheets(ws).Range("A" & lastRow).Interior.Color = vbYellow
    If Sheets(ws).Range("D5") = "LOW" Then Sheets(ws).Range("A" & lastRow).Interior.Color = vbRed
    If Sheets(ws).Range("D5") = "HIGH" Then Sheets(ws).Range("B" & lastRow).Interior.Color = vbGreen
    If Sheets(ws).Range("D5") = "MEDIUM" Then Sheets(ws).Range("B" & lastRow).Interior.Color = vbYellow
    If Sheets(ws).Range("D5") = "LOW" Then Sheets(ws).Range("B" & lastRow).Interior.Color = vbRed
    If Sheets(ws).Range("D5") = "HIGH" Then Sheets(ws).Range("C" & lastRow).Interior.Color = vbGreen
    If Sheets(ws).Range("D5") = "MEDIUM" Then Sheets(ws).Range("C" & lastRow).Interior.Color = vbYellow
    If Sheets(ws).Range("D5") = "LOW" Then Sheets(ws).Range("C" & lastRow).Interior.Color = vbRed
    If Sheets(ws).Range("D5") = "HIGH" Then Sheets(ws).Range("D" & lastRow).Interior.Color = vbGreen
    If Sheets(ws).Range("D5") = "MEDIUM" Then Sheets(ws).Range("D" & lastRow).Interior.Color = vbYellow
    If Sheets(ws).Range("D5") = "LOW" Then Sheets(ws).Range("D" & lastRow).Interior.Color = vbRed
    Sheets(ws).Range("A5:D5").Copy
    Sheets(ws).Range("A" & lastRow).PasteSpecial xlPasteValues
   
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,382
Messages
6,119,194
Members
448,874
Latest member
Lancelots

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