Change to different color

Holyfix

New Member
Joined
Oct 14, 2021
Messages
9
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hey, I have currently made a macro to add 3 columns before the last column with data, but I need the last column out of these 3 added and also first row to be always different colour (it doesn't have to be random, just a range of 10 colors repeating). This is what it looks like:

VBA Code:
Sub ADD()
    Dim LastCol As Long
    Dim Lastrow As Integer
     
    'COPY
    Columns("A:C").Copy
    
    'COLUMNS
    LastCol = ActiveSheet.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
    Columns(LastCol).Insert
    
    'DELETE DATA
    Columns(LastCol).Range("A3:B3" & Lastrow).ClearContents
    
    'CHANGE OF COLOR
    Columns(LastCol).Range("A1:C1").Interior.ColorIndex = 4
    Columns(LastCol).Offset(, 2).Interior.ColorIndex = 4
    
End Sub

Thank you very much for your help !!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
How about
VBA Code:
Sub Holyfix()
    Dim LastCol As Long
    Dim Lastrow As Integer
    Dim Clr As Long
    
    'COPY
    Columns("A:C").Copy
    
    'COLUMNS
    LastCol = ActiveSheet.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
    Columns(LastCol).Insert
    
    'DELETE DATA
    Columns(LastCol).Range("A3:B3" & Lastrow).ClearContents
    
    'CHANGE OF COLOR
    Clr = Columns(LastCol).Offset(, -1).Interior.ColorIndex
    If Clr = 13 Or Clr < 0 Then Clr = 4 Else Clr = Clr + 1
    Columns(LastCol).Range("A1:C1").Interior.ColorIndex = Clr
    Columns(LastCol).Offset(, 2).Interior.ColorIndex = Clr
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,934
Members
449,094
Latest member
teemeren

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