Selecting and formatting range dependendat on cell content in column

RhodEvans

Board Regular
Joined
Oct 31, 2012
Messages
88
Afternoon,

I'm sure this is simple, but I can't get my head round it.
I have a workbook that aggregates 3 separate worksheets onto a 'summary' sheet then sorts it into weekday order.

Code:
Private Sub Worksheet_Activate()

Application.ScreenUpdating = False

Range("A9:G4000").Select
Range("A9:G4000").Clear
Selection.ClearFormats

' CDVP
Dim nextrow As Long
nextrow = Cells(4000, 1).End(xlUp).Row + 1
If nextrow < 2 Then nextrow = 2
If nextrow > 4000 Then
    MsgBox ("The next empty row is outside the range, IdioT!"), vbExclamation
    Exit Sub
End If

Dim rng
Set rng = Worksheets("CDVP").UsedRange
Intersect(rng, rng.Offset(1)).Copy

Range("A" & nextrow).Select
ActiveSheet.Paste

' TSP

nextrow = Cells(4000, 1).End(xlUp).Row + 1
If nextrow < 2 Then nextrow = 2
If nextrow > 4000 Then
    MsgBox ("The next empty row is outside the range, IdioT!"), vbExclamation
    Exit Sub
End If


Set rng = Worksheets("TSP").UsedRange
Intersect(rng, rng.Offset(1)).Copy

Range("A" & nextrow).Select
ActiveSheet.Paste

' SOGP

nextrow = Cells(4000, 1).End(xlUp).Row + 1
If nextrow < 2 Then nextrow = 2
If nextrow > 4000 Then
    MsgBox ("The next empty row is outside the range, IdioT!"), vbExclamation
    Exit Sub
End If

Set rng = Worksheets("SOGP").UsedRange
Intersect(rng, rng.Offset(1)).Copy

Range("A" & nextrow).Select
ActiveSheet.Paste

    Cells.Select
     Selection.RowHeight = 25
    Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _
        , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=3, MatchCase:= _
        False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
        :=xlSortNormal
        
            Columns("D:D").Select
    Selection.Style = "Currency"
    
Dim myrange As Range
Dim icounter As Long

Set myrange = ActiveSheet.UsedRange

For icounter = myrange.Rows.Count To 1 Step -1

If Application.CountA(Rows(icounter).EntireRow) = 0 Then
Rows(icounter).Delete
End If

Next icounter

Application.ScreenUpdating = True
End Sub

I'm sure this is not the most efficient coding ever, but it does work.

What I am trying to then do is to add a thick border round Each section (day of the week.

My sheet is as follows:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[TD]E
[/TD]
[TD]F
[/TD]
[TD]G
[/TD]
[TD]H
[/TD]
[TD]I
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Weekday
[/TD]
[TD]Group
[/TD]
[TD]Stuff
[/TD]
[TD]Stuff
[/TD]
[TD]Stuff
[/TD]
[TD]Stuff
[/TD]
[TD]Stuff
[/TD]
[TD]Stuff
[/TD]
[TD]Stuff
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]Monday
[/TD]
[TD]TSP
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]Monday
[/TD]
[TD]SGP
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]Tuesday
[/TD]
[TD]TSP
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]Tuesday
[/TD]
[TD]TSP
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]Tuesday
[/TD]
[TD]SGP
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7
[/TD]
[TD]Wednesday
[/TD]
[TD]BPR
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8
[/TD]
[TD]Thursday
[/TD]
[TD]SMR
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

So with the example above I would like it to have a thick border around A2:I3, A4:I6, A7:I7, A8:I8.
Because the info is dynamic I wont know where these are only that the Day of the week will be in column 1 and that they will always be sorted into weekday order.
I hope this all makes sense and is probably easier than I have explained it. But, I am always grateful for any assistance i can get.

Thank you in advance
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,223,723
Messages
6,174,113
Members
452,544
Latest member
aush

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