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:
A
B
C
D
E
F
G
H
I
1
Weekday
Group
Stuff
Stuff
Stuff
Stuff
Stuff
Stuff
Stuff
2
Monday
TSP
3
Monday
SGP
4
Tuesday
TSP
5
Tuesday
TSP
6
Tuesday
SGP
7
Wednesday
BPR
8
Thursday
SMR

<tbody>
</tbody>

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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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