VBA to consolidate list

hwong8848

New Member
Joined
Oct 9, 2022
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi all! I have a list of task and company names on column D and the respective status in column E in sheet Jan 16.
I'd like to have a button to update a table in the Sheet name Consol, which the heading is the status and I like to return Column D in the table to the end until it reach the # (this row is not static, because I might add new task in-between columns or remove from time to time)

This is the list on Jan 16.
workbook1.xlsx
ABCDE
15BEANon-executive Benchmarking & STI reviewBEA Non-executive Benchmarking & STI reviewLOST
16COSCO ShippingInvestment team pay structureCOSCO SHIPPING Investment team pay structureClosing
17HKICLPay Trend HKICL Pay Trend Preparing Proposal
18HKLand Job Matching+Pay BenchmarkingHKLAND Job Matching+Pay BenchmarkingCLOSED
19HKMAPay trendHKMA Pay trendMilestone
20HKMCHKMC CLOSED
21HKTDCpay level reviewHKTDC pay level reviewPreparing Proposal
22MPFAPay review + rating distributionMPFA Pay review + rating distributionClosing
23PGSJE + pay rangePGS JE + pay rangeMIA
24Swire Propertiesgrading, pay and benefitsSWIRE PROPERTIES grading, pay and benefitsMilestone
25
26AIARemCo AdvisoryAIA RemCo AdvisorySubmitted / Waiting
27AXAAPAC team for a Paris projectAXA APAC team for a Paris projectNew Project
28Bank of China HKPay Assessment for Top ManagementBANK OF CHINA HK Pay Assessment for Top ManagementLOST
29Best AssistantPre-IPO supportBEST ASSISTANT Pre-IPO supportPreparing Proposal
30Chen HsongRemCo meeting supportCHEN HSONG RemCo meeting supportSubmitted / Waiting
31China State Construction EngineeringIncentive/ retention programCHINA STATE CONSTRUCTION ENGINEERING Incentive/ retention programCLOSED
32COSCO ShippingLTICOSCO SHIPPING LTILOST
33Hysan DevelopmentLTI designHYSAN DEVELOPMENT LTI designMIA
34MaximPay philosophy workshopMAXIM Pay philosophy workshopClosing
35Peak ReEC BenchmarkingPEAK RE EC BenchmarkingNew Project
36Phase ScientificLTI ProjectPHASE SCIENTIFIC LTI ProjectClosing
37Prudential plcEC BenchmarkingPRUDENTIAL PLC EC BenchmarkingClosing
38Prudential plcRemCo AdvisoryPRUDENTIAL PLC RemCo AdvisoryLOST
39QCPExecutive benchmark and incentiveQCP Executive benchmark and incentiveSubmitted / Waiting
40RPDA2022 data collectionRPDA 2022 data collectionPreparing Proposal
41Shui On LandExec benchmark and LTI designSHUI ON LAND Exec benchmark and LTI designSubmitted / Waiting
42SOCAMLTI design workSOCAM LTI design workContracting
43StarHubTotal comp reviewSTARHUB Total comp reviewMilestone
44Swiss ReEC BenchmarkingSWISS RE EC BenchmarkingLOST
45
46BEA (Bank of East Asia)EESBEA (BANK OF EAST ASIA) EESNew Project
47CCBAEES - Internal Support ServicesCCBA EES - Internal Support ServicesLOST
48CMHKEES CMHK EES Submitted / Waiting
49DFSComms Support on Rewards OfferingDFS Comms Support on Rewards OfferingCLOSED
50Eaton HKEES licenseEATON HK EES licenseClosing
51Huatai Financial HoldingsEES License + VFGHUATAI FINANCIAL HOLDINGS EES License + VFGCLOSED
52Langham Hotel GroupEES LANGHAM HOTEL GROUP EES Closing
53Mandarin Oriential Hotel GroupEESMANDARIN ORIENTIAL HOTEL GROUP EESInitial Discussion
54PGSLeadership developmentPGS Leadership developmentContracting
55VitasoyEESVITASOY EESPreparing Proposal
56
57AIAbenchmarking of IA positionsAIA benchmarking of IA positionsInitial Discussion
58ALDI Asia LimitedSurvey+focus groupALDI ASIA LIMITED Survey+focus groupPreparing Proposal
59AnimocaBrandsJob levellingANIMOCABRANDS Job levellingSubmitted / Waiting
60ASMgrading structure validationASM grading structure validationPreparing Proposal
61Aureconpay competitive analysis & STI reviewAURECON pay competitive analysis & STI reviewPreparing Proposal
62Automated Systems LimitedEESAUTOMATED SYSTEMS LIMITED EESMIA
63BDX EESBDX EESNew Project
64CCBASaville assessmentCCBA Saville assessmentSubmitted / Waiting
65China Harbour Eng HKGrading structure, perf mgmt, comp reviewCHINA HARBOUR ENG HK Grading structure, perf mgmt, comp reviewPreparing Proposal
66China Investment Holdings Limited CHINA INVESTMENT HOLDINGS LIMITED Preparing Proposal
67China Resources CapitalInvestment team setupCHINA RESOURCES CAPITAL Investment team setupSubmitted / Waiting
68CityU VMCEESCITYU VMC EESSubmitted / Waiting
69CLP EESCLP EESMIA
70Cyberportpay benefitCYBERPORT pay benefitPreparing Proposal
71ESFInt'l SchoolESF Int'l SchoolContracting
72Fusion BankLTI Plan DesignFUSION BANK LTI Plan DesignCLOSED
73GDSTBCGDS TBCCLOSED
74GEGEmployee Experience Strategy and Listening ApproachGEG Employee Experience Strategy and Listening ApproachSubmitted / Waiting
75Global GloryTotal comp strategy designGLOBAL GLORY Total comp strategy designNew Project
76HarrowSponsor surveyHARROW Sponsor surveyNew Project
77HK Electricpay benchmarkingHK ELECTRIC pay benchmarkingContracting
78HKJCPay + STIHKJC Pay + STIClosing
79HKSTPPHASE 2: Pay philosophy & GradingHKSTP PHASE 2: Pay philosophy & GradingCLOSED
80HKSTPInvestment team pay structureHKSTP Investment team pay structureSubmitted / Waiting
81HSBCSurveyHSBC SurveyMilestone
82Hysan DevelopmentLTI designHYSAN DEVELOPMENT LTI designPreparing Proposal
83IQAX (OOCL)Pay benchmarking for IT jobsIQAX (OOCL) Pay benchmarking for IT jobsClosing
84KMBPay ReviewKMB Pay ReviewSubmitted / Waiting
85LCSDJob PricingLCSD Job PricingNew Project
86Lee Kam KeeEESLEE KAM KEE EESSubmitted / Waiting
87Maxim'sEESMAXIM'S EESLOST
88MeiyumeRewards StrategyMEIYUME Rewards StrategyPreparing Proposal
89Paul Y EngineeringEESPAUL Y ENGINEERING EESMIA
90PreneticsJob pricingPRENETICS Job pricingLOST
91Qatar Investment AuthoritySTI & Incentive designQATAR INVESTMENT AUTHORITY STI & Incentive designPreparing Proposal
92Sompojob matchingSOMPO job matchingSubmitted / Waiting
93Swire PropertiesEESSWIRE PROPERTIES EESContracting
94Taishin (TW)PulseTAISHIN (TW) PulseClosing
95VingroupLTI designVINGROUP LTI designMilestone
96YWCASaville assessmentYWCA Saville assessmentPreparing Proposal
97#####
98INTERNAL STUFF
99xx
100xxxx
101x
102xxx
103xxx
104
Jan 16
Cell Formulas
RangeFormula
D15:D24,D57:D96,D46:D55,D26:D44D15=UPPER(B15)&" "&C15
Cells with Data Validation
CellAllowCriteria
E15:E24List=MISC!$A$2:$A$11
E57:E96List=MISC!$A$2:$A$11
E46:E55List=MISC!$A$2:$A$11
E26:E44List=MISC!$A$2:$A$11


And this is the Consol table as example, the macro has to clear everything each time it updates to avoid duplicating data or misplacing it.
Since my list of task and company names is forever expanding, i need the macro to add new rolls or delete empty rolls as I update it every week as well.

workbook1.xlsx
BCDEFGH
2Initial DiscussionPreparing ProposalSubmitted / WaitingContractingNew ProjectMilestoneClosing
3COSCO SHIPPING Investment team pay structureCHINA STATE CONSTRUCTION ENGINEERING Incentive/ retention programBEA Non-executive Benchmarking & STI review
4HKICL Pay Trend
5
6
7
8
9
10
11
12
13
14
15MIALOSTCLOSED
16
17
18
19
20
21
22
Consol


Much Appreciated!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try this:

VBA Code:
Sub Consol()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim st1 As Variant, st2 As Variant
  Dim i As Long, lr As Long, nRow As Long, lr1 As Long, lr2 As Long
  Dim c As Range, f As Range
  
  Set sh1 = Sheets("Jan 16")
  Set sh2 = Sheets("Consol")
  
  Set f = sh1.Range("E:E").Find("#", , xlValues, xlPart, xlByRows, xlPrevious)
  If Not f Is Nothing Then lr = f.Row - 1 Else lr = sh1.Range("E" & Rows.Count).End(3).Row
  
  st1 = Array("Initial Discussion", "Preparing Proposal", "Submitted / Waiting", "Contracting", "New Project", "Milestone", "Closing")
  st2 = Array("", "MIA", "LOST", "", "", "", "CLOSED")
  
  Application.ScreenUpdating = False
  sh2.Cells.Clear
  sh2.Range("B2").Resize(1, UBound(st1) + 1).Value = st1
  sh2.Range("J2").Resize(1, UBound(st2) + 1).Value = st2
    
  For Each c In sh1.Range("E2", sh1.Range("E" & Rows.Count).End(3))
    If c.Value <> "" Then
      Set f = sh2.Range("2:2").Find(c.Value, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        nRow = sh2.Cells(Rows.Count, f.Column).End(3).Row + 1
        sh2.Cells(nRow, f.Column).Value = c.Offset(, -1).Value
      End If
    End If
  Next
  
  Set f = sh2.Range("B:H").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  lr1 = f.Row + 2
  
  Set f = sh2.Range("J:P").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  lr2 = f.Row
  
  sh2.Range("J2:P" & lr2).Cut sh2.Range("B" & lr1)

  With sh2.Range("B2:H2")
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
  End With
  
  With sh2.Range("B" & lr1 & ":H" & lr1)
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
  End With
  
  With sh2.Range("B:H")
    .WrapText = True
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
  End With

  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Works great!! Few questions though
I have input some code to create boarder on my table, not sure this is the best way - hope you can let me know!!
Furthermore, is there a way to sort the list by alphabetical order before pasting in the table?

VBA Code:
Sub Consol()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim st1 As Variant, st2 As Variant
  Dim i As Long, lr As Long, nRow As Long, lr1 As Long, lr2 As Long
  Dim c As Range, f As Range
  
  Set sh1 = ActiveSheet
  Set sh2 = Sheets("Consol")
  
  Set f = sh1.Range("E:E").Find("#", , xlValues, xlPart, xlByRows, xlPrevious)
  If Not f Is Nothing Then lr = f.Row - 1 Else lr = sh1.Range("E" & Rows.Count).End(3).Row
  
  st1 = Array("Initial Discussion", "Preparing Proposal", "Submitted / Waiting", "Contracting", "New Project", "Milestone", "Closing")
  st2 = Array("", "MIA", "LOST", "", "", "", "CLOSED")
  
  Application.ScreenUpdating = False
  sh2.Cells.Clear
  sh2.Range("B2").Resize(1, UBound(st1) + 1).Value = st1
  sh2.Range("J2").Resize(1, UBound(st2) + 1).Value = st2
    
  For Each c In sh1.Range("E2", sh1.Range("E" & Rows.Count).End(3))
    If c.Value <> "" Then
      Set f = sh2.Range("2:2").Find(c.Value, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        nRow = sh2.Cells(Rows.Count, f.Column).End(3).Row + 1
        sh2.Cells(nRow, f.Column).Value = c.Offset(, -1).Value
      End If
    End If
  Next
  
  Set f = sh2.Range("B:H").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  lr1 = f.Row + 2
  
  Set f = sh2.Range("J:P").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  lr2 = f.Row
  
  sh2.Range("J2:P" & lr2).Cut sh2.Range("B" & lr1)

  With sh2.Range("B2:H2")
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
  End With
  
  With sh2.Range("B" & lr1 & ":H" & lr1)
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
  End With
  
  With sh2.Range("B:H")
    .WrapText = True
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
  End With

Dim iRange As Range
Dim iCells As Range

Set iRange = sh2.UsedRange
'Format with boarder
For Each iCells In iRange
    If Not IsEmpty(iCells) Then
    iCells.BorderAround _
            LineStyle:=xlContinuous, _
            Weight:=xlThin
    End If
Next iCells

  Application.ScreenUpdating = True
End Sub
 
Upvote 0
I have input some code to create boarder on my table, not sure this is the best way - hope you can let me know!!
Furthermore, is there a way to sort the list by alphabetical order before pasting in the table?

Try this:

VBA Code:
Sub Consol()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim st1 As Variant, st2 As Variant
  Dim i As Long, lr As Long, nRow As Long, lr1 As Long, lr2 As Long
  Dim c As Range, f As Range
 
  Set sh1 = ActiveSheet
  Set sh2 = Sheets("Consol")
 
  Set f = sh1.Range("E:E").Find("#", , xlValues, xlPart, xlByRows, xlPrevious)
  If Not f Is Nothing Then lr = f.Row - 1 Else lr = sh1.Range("E" & Rows.Count).End(3).Row
 
  st1 = Array("Initial Discussion", "Preparing Proposal", "Submitted / Waiting", "Contracting", "New Project", "Milestone", "Closing")
  st2 = Array("", "MIA", "LOST", "", "", "", "CLOSED")
 
  Application.ScreenUpdating = False
  sh2.Cells.Clear
  sh2.Range("B2").Resize(1, UBound(st1) + 1).Value = st1
  sh2.Range("J2").Resize(1, UBound(st2) + 1).Value = st2
   
  For Each c In sh1.Range("E2", sh1.Range("E" & Rows.Count).End(3))
    If c.Value <> "" Then
      Set f = sh2.Range("2:2").Find(c.Value, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        nRow = sh2.Cells(Rows.Count, f.Column).End(3).Row + 1
        sh2.Cells(nRow, f.Column).Value = c.Offset(, -1).Value
      End If
    End If
  Next
 
  Set f = sh2.Range("B:H").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  lr1 = f.Row + 2
  Set f = sh2.Range("J:P").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  lr2 = f.Row
 
  'sort the list
  For j = Columns("B").Column To Columns("P").Column
    If sh2.Cells(4, j).Value <> "" Then
      sh2.Range(sh2.Cells(2, j), sh2.Cells(lr1, j)).Sort key1:=sh2.Cells(2, j), _
        order1:=xlAscending, Header:=xlYes
    End If
  Next
 
  'Paste second block of data
  sh2.Range("J2:P" & lr2).Cut sh2.Range("B" & lr1)
 
  'Title format
  With sh2.Range("B2:H2")
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
  End With
  With sh2.Range("B" & lr1 & ":H" & lr1)
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
  End With
  With sh2.Range("B:H")
    .WrapText = True
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
  End With

  'Format with boarder
  sh2.UsedRange.SpecialCells(xlCellTypeConstants).Borders.LineStyle = xlContinuous

  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
This definitely looks easier.
Last question, I have edited some title so I extended the range.
Is there a way to color the column differently such as this?
1672906102532.png


I have collected the RGB color I want:

B 247,213,241
C 218, 194, 236
D 189,215,238
E 198,224,180
F 248, 203, 173
G 255, 230, 153
H 217, 217, 217
I 166,166,166

I tried to do so using usedrange but it will color the title as well which I don't one..

VBA Code:
Sub consolidate()
  Application.ScreenUpdating = False
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim st1 As Variant, st2 As Variant
  Dim i As Long, lr As Long, nRow As Long, lr1 As Long, lr2 As Long
  Dim c As Range, f As Range
 
  Set sh1 = ActiveSheet
  Set sh2 = Sheets("Pipeline")
 
  Set f = sh1.Range("E:E").Find("#", , xlValues, xlPart, xlByRows, xlPrevious)
  If Not f Is Nothing Then lr = f.Row - 1 Else lr = sh1.Range("E" & Rows.Count).End(3).Row
 
  st1 = Array("Initial Discussion", "Preparing Proposal", "Submitted / Waiting", "Contracting", "New Project", "Milestone", , "Sunsetting", "Closing")
  st2 = Array("", "MIA", "LOST", "", "", "", "CLOSED")
 

  sh2.Cells.Clear
  sh2.Range("B2").Resize(1, UBound(st1) + 1).Value = st1
  sh2.Range("K2").Resize(1, UBound(st2) + 1).Value = st2
   
  For Each c In sh1.Range("E2", sh1.Range("E" & Rows.Count).End(3))
    If c.Value <> "" Then
      Set f = sh2.Range("2:2").Find(c.Value, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        nRow = sh2.Cells(Rows.Count, f.Column).End(3).Row + 1
        sh2.Cells(nRow, f.Column).Value = c.Offset(, -1).Value
      End If
    End If
  Next
 
  Set f = sh2.Range("B:I").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  lr1 = f.Row + 2
  Set f = sh2.Range("K:R").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  lr2 = f.Row
 
  'sort the list
  For j = Columns("B").Column To Columns("R").Column
    If sh2.Cells(4, j).Value <> "" Then
      sh2.Range(sh2.Cells(2, j), sh2.Cells(lr1, j)).Sort key1:=sh2.Cells(2, j), _
        order1:=xlAscending, Header:=xlYes
    End If
  Next
 
  'Paste second block of data
  sh2.Range("K2:R" & lr2).Cut sh2.Range("B" & lr1)
 
  'Title format
  With sh2.Range("B2:I2")
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
  End With
  With sh2.Range("B" & lr1 & ":I" & lr1)
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
  End With
  With sh2.Range("B:I")
    .WrapText = True
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
  End With

  'Format with boarder
  sh2.UsedRange.SpecialCells(xlCellTypeConstants).Borders.LineStyle = xlContinuous
  
  'Format row height
  sh2.UsedRange.EntireRow.AutoFit
  
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
VBA Code:
Sub consolidate()
  Application.ScreenUpdating = False
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim st1 As Variant, st2 As Variant
  Dim i As Long, lr As Long, nRow As Long, lr1 As Long, lr2 As Long
  Dim c As Range, f As Range
 
  Set sh1 = ActiveSheet
  Set sh2 = Sheets("Pipeline")
 
  Set f = sh1.Range("E:E").Find("#", , xlValues, xlPart, xlByRows, xlPrevious)
  If Not f Is Nothing Then lr = f.Row - 1 Else lr = sh1.Range("E" & Rows.Count).End(3).Row
 
  st1 = Array("Initial Discussion", "Preparing Proposal", "Submitted / Waiting", "Contracting", "New Project", "Milestone", "Sunsetting", "To Close")
  st2 = Array("", "MIA", "LOST", "", "", "", "CLOSED")
 

  sh2.Cells.Clear
  sh2.Range("B2").Resize(1, UBound(st1) + 1).Value = st1
  sh2.Range("K2").Resize(1, UBound(st2) + 1).Value = st2
   
  For Each c In sh1.Range("E2", sh1.Range("E" & Rows.Count).End(3))
    If c.Value <> "" Then
      Set f = sh2.Range("2:2").Find(c.Value, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        nRow = sh2.Cells(Rows.Count, f.Column).End(3).Row + 1
        sh2.Cells(nRow, f.Column).Value = c.Offset(, -1).Value
      End If
    End If
  Next
 
  Set f = sh2.Range("B:I").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  lr1 = f.Row + 2
  Set f = sh2.Range("K:R").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  lr2 = f.Row
 
  'sort the list
  For j = Columns("B").Column To Columns("R").Column
    If sh2.Cells(4, j).Value <> "" Then
      sh2.Range(sh2.Cells(2, j), sh2.Cells(lr1, j)).Sort key1:=sh2.Cells(2, j), _
        order1:=xlAscending, Header:=xlYes
    End If
  Next
 
  'Paste second block of data
  sh2.Range("K2:R" & lr2).Cut sh2.Range("B" & lr1)
  
  'Color Format
  With sh2.Range("B" & lr1)
    .Interior.Color = RGB(247, 213, 241)
  End With
    With sh2.Range("C" & lr1)
    .Interior.Color = RGB(218, 194, 236)
  End With
    With sh2.Range("D" & lr1)
    .Interior.Color = RGB(189, 215, 238)
  End With
    With sh2.Range("E" & lr1)
    .Interior.Color = RGB(198, 224, 180)
  End With
    With sh2.Range("F" & lr1)
    .Interior.Color = RGB(248, 203, 173)
  End With
    With sh2.Range("G" & lr1)
    .Interior.Color = RGB(255, 230, 153)
  End With
    With sh2.Range("H" & lr1)
    .Interior.Color = RGB(217, 217, 217)
  End With
      With sh2.Range("I" & lr1)
    .Interior.Color = RGB(166, 166, 166)
  End With
    
  'Title format
  With sh2.Range("B2:i2")
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
  End With
  With sh2.Range("B" & lr1 & ":i" & lr1)
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
  End With


  'Format with boarder
  sh2.UsedRange.SpecialCells(xlCellTypeConstants).Borders.LineStyle = xlContinuous
  
  'Format row height
  sh2.UsedRange.RowHeight = 50
  
  With sh2.Range("B:i")
    .WrapText = True
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
  End With
  
  Application.ScreenUpdating = True
End Sub

Felt like I misunderstood the code somewhere, but I input all the color in for now
 
Upvote 0
VBA Code:
Sub LastRowInOneColumn()
'Find the last used row in a Column: column A in this example
    Dim LastRow As Long
    Set sh2 = Sheets("Pipeline")
    With sh2
        LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
        With sh2.Range("B2:B" & LastRow)
            .Interior.Color = RGB(247, 213, 241)
        End With
    End With
       With sh2
        LastRow = .Cells(.Rows.Count, "c").End(xlUp).Row
        With sh2.Range("c2:c" & LastRow)
            .Interior.Color = RGB(218, 194, 236)
        End With
    End With
  
End Sub

I have create this code to highlight the cells range in different color, but it highlight blank cell and title as well, is there a way to skip those?
 
Upvote 0
VBA Code:
Sub LastRowInOneColumn()
'Find the last used row in a Column: column A in this example
    Dim LastRow As Long
    Set sh2 = Sheets("Pipeline")
    With sh2
        LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
        With sh2.Range("B2:B" & LastRow)
            .Interior.Color = RGB(247, 213, 241)
        End With
    End With
       With sh2
        LastRow = .Cells(.Rows.Count, "c").End(xlUp).Row
        With sh2.Range("c2:c" & LastRow)
            .Interior.Color = RGB(218, 194, 236)
        End With
    End With
 
End Sub

I have create this code to highlight the cells range in different color, but it highlight blank cell and title as well, is there a way to skip those?
I used a dumb way to color the column with different color and remove formatting for empty cell.

VBA Code:
Sub FORMAT()

    Dim LastRow As Long, lr3 As Long, i As Long, c As Long
    Dim xcell As Range, xrange As Range
    Dim sh2 As Worksheet
    
    Set sh2 = Sheets("Pipeline")
    
    With sh2
        LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
        With sh2.Range("B2:B" & LastRow)
            .Interior.Color = RGB(247, 213, 241)
        End With
    End With
    
    With sh2
        LastRow = .Cells(.Rows.Count, "c").End(xlUp).Row
        With sh2.Range("c2:c" & LastRow)
            .Interior.Color = RGB(218, 194, 236)
        End With
    End With
    
    With sh2
        LastRow = .Cells(.Rows.Count, "d").End(xlUp).Row
        With sh2.Range("d2:d" & LastRow)
            .Interior.Color = RGB(189, 215, 238)
        End With
    End With
    
    With sh2
        LastRow = .Cells(.Rows.Count, "e").End(xlUp).Row
        With sh2.Range("e2:e" & LastRow)
            .Interior.Color = RGB(198, 224, 180)
        End With
    End With
    
    With sh2
        LastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
        With sh2.Range("F2:F" & LastRow)
            .Interior.Color = RGB(248, 203, 173)
        End With
    End With
    
    With sh2
        LastRow = .Cells(.Rows.Count, "G").End(xlUp).Row
        With sh2.Range("G2:G" & LastRow)
            .Interior.Color = RGB(255, 230, 153)
        End With
    End With
    
    With sh2
        LastRow = .Cells(.Rows.Count, "H").End(xlUp).Row
        With sh2.Range("H2:H" & LastRow)
            .Interior.Color = RGB(217, 217, 217)
        End With
    End With
    
    With sh2
        LastRow = .Cells(.Rows.Count, "I").End(xlUp).Row
        With sh2.Range("I2:I" & LastRow)
            .Interior.Color = RGB(166, 166, 166)
        End With
    End With
    
    lr3 = sh2.Cells.Find(What:="*", _
                    After:=Range("B1"), _
                    LookAt:=xlPart, _
                    LookIn:=xlFormulas, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious, _
                    MatchCase:=False).Row
                    
    Set xrange = sh2.Range("B3:I" & lr3)
    
    For Each xcell In xrange
        If IsEmpty(xcell) Then
           xcell.Interior.Color = RGB(255, 255, 255)
        End If
        
    Next xcell
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,403
Members
452,325
Latest member
BlahQz

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