[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

add ing borders using vba

Asked by LINNANDA in VB Script

Hi,

I've a macro which formats a sheet

Model1 -

                                   Group1               Group2                Group3              
                            Model  Act Var       Model  Act Var   Model  Act Var

Model 2

                                   Group1               Group2                Group3              
                            Model  Act Var       Model  Act Var   Model  Act Var


Model 3
                             
                                   Group1               Group2                Group3              
                            Model  Act Var       Model  Act Var   Model  Act Var


Model in Group1 is always ColumnD
Act  in Group1 is always ColumnE
Var l in Group1 is always ColumnF

Model in Group2 is always ColumnH
Act  in Group2 is always ColumnI
Var l in Group2 is always ColumnJ

Model in Group3 is always ColumnL
Act  in Group3 is always ColumnM
Var l in Group3 is always ColumnN

I need to put borders around each of the three groups

for example

Range("D8:F10").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 1
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 1
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 1
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 1
    End With

Currently the code is

 Sub Csformatting_6()
   
       'Dim wks As Worksheet
    'For Each wks In ActiveWorkbook.Worksheets
     
   
    'Dim wks As Worksheet
'For Each wks In ActiveWorkbook.Worksheets
'wks.Select
   
   
        Cells.Select
    Selection.Sort Key1:=Range("G2"), Order1:=xlDescending, Key2:=Range("C2") _
        , Order2:=xlAscending, header:=xlGuess, OrderCustom:=1, MatchCase:= _
        False, Orientation:=xlTopToBottom
    Rows("1:1").Select
    Selection.Insert Shift:=xlDown
    Selection.Insert Shift:=xlDown
    Selection.Insert Shift:=xlDown
    Range("A9").Select
   
   
        Cells.Select
   
    Range("A:Z").Activate
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 15
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 15
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 15
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 15
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 15
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 15
    End With
   
    Call Model_b
    Call Model_c
    Call Model_d
   
       
          For lRow = 2 To Cells.SpecialCells(xlCellTypeLastCell).row
             
                If Cells(lRow, 1).Value <> " " Then
             
                   
                    Range("K" & lRow).NumberFormat = "0%"
                    Range("L" & lRow).NumberFormat = "0%"
                    Range("O" & lRow).NumberFormat = "0%"
                    Range("P" & lRow).NumberFormat = "0%"
             
                    Range("S" & lRow).NumberFormat = "0%"
                    Range("T" & lRow).NumberFormat = "0%"
                    Range("W" & lRow).NumberFormat = "0%"
                    Range("X" & lRow).NumberFormat = "0%"  
              End If
           
        Next lRow
       
       
    Columns("C:H").Select
    Range("H1").Activate
    Selection.Delete Shift:=xlToLeft
    Columns("G:G").Select
    Selection.Delete Shift:=xlToLeft
       
    Columns("J:J").Select
       Selection.Delete Shift:=xlToLeft
       
    Columns("M:M").Select
       Selection.Delete Shift:=xlToLeft
    Columns("P:P").Select
        Selection.Delete Shift:=xlToLeft
   
   
    Columns("C:C").Select
        Selection.Delete Shift:=xlToLeft
   
    Rows("4:4").Select
    Selection.Delete Shift:=xlUp
   
    Columns("A:A").ColumnWidth = 17.14
 
   
    '
    ActiveWindow.Zoom = 75
       
       
         Range("A4").Select
         ActiveCell.Value = "Discretionary Accounts"
         
    With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .MergeCells = False
        .Font.Size = 12
        .Font.ColorIndex = 1
    End With
       
       
       
    Columns("F:F").Select
    Selection.Insert Shift:=xlToRight
    Columns("J:J").Select
    Selection.Insert Shift:=xlToRight
    Columns("N:N").Select
    Selection.Insert Shift:=xlToRight
    Range("A1").Select
       

Columns("A:A").ColumnWidth = 14
Columns("B:B").ColumnWidth = 36

    Columns("D:D").ColumnWidth = 7.57
    Columns("E:E").ColumnWidth = 9.43
     Columns("F:F").ColumnWidth = 7.29
    Columns("H:H").ColumnWidth = 8.86
    Columns("I:I").ColumnWidth = 10.29
    Columns("M:M").ColumnWidth = 8.57
    Columns("L:L").ColumnWidth = 7.14
    Columns("N:N").ColumnWidth = 7.86
    Columns("O:O").ColumnWidth = 6.14
   
    Columns("P:P").ColumnWidth = 8.14
    Columns("Q:Q").ColumnWidth = 8.43

         Rows("4:4").Select
    Selection.Delete Shift:=xlUp
             
        Rows("4:4").Select
    Selection.Delete Shift:=xlUp              
             
              End If
   
        Columns("C:C").Select
    Selection.Insert Shift:=xlToRight
    Range("C6").Select
    Columns("C:C").ColumnWidth = 2.86
   
   'Next
   
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub Model_b()

col = 3 'your column number
startRow = 1 ' Row where the data starts
col_header = 1
col7 = 7
RowsA = Cells(Rows.Count, col).End(xlUp).row
For i = startRow To RowsA
    If Cells(i, col) = "B" And Cells(i, col7) = "D" Then
        For j = 1 To 5
            Rows(i).EntireRow.Insert
          Next j
          Cells(i + 2, col_header).Value = "Model 1"
         
         
             With Cells(i + 2, col_header)
             '   .Value = "Model 1"
                .Font.Bold = True
                .Font.ColorIndex = 1
                .HorizontalAlignment = xlLeft

             End With
         
       
          Cells(i + 3, col_header + 10).Value = "Group1"
 
            With Cells(i + 3, col_header + 10)
            .HorizontalAlignment = xlCenter
               .Font.Bold = True
               .Font.ColorIndex = 1
            End With

               
          Cells(i + 4, col7 + 3).Value = "Model"
         
              With Cells(i + 4, col7 + 3)
               .Font.Bold = True
               .Font.ColorIndex = 1
              End With
         
          Cells(i + 4, col7 + 4).Value = "Act"
         
                  With Cells(i + 4, col7 + 4)
                   .Font.Bold = True
                   .Font.ColorIndex = 1
                   End With
         
          Cells(i + 4, col7 + 5).Value = "Var"
                 With Cells(i + 4, col7 + 5)
                   .Font.Bold = True
                   .Font.ColorIndex = 1
                   End With
                               
         
        Cells(i + 3, col_header + 14).Value = "Group2"
         
                   With Cells(i + 3, col_header + 14)
                        .Font.Bold = True
                        .Font.ColorIndex = 1
                   End With
         
          Cells(i + 4, col7 + 7).Value = "Model"
                     With Cells(i + 4, col7 + 7)
                        .Font.Bold = True
                        .Font.ColorIndex = 1
                   End With
         
          Cells(i + 4, col7 + 8).Value = "Act"
                    With Cells(i + 4, col7 + 8)
                        .Font.Bold = True
                         .Font.ColorIndex = 1
                   End With
                   
          Cells(i + 4, col7 + 9).Value = "Var"
                    With Cells(i + 4, col7 + 9)
                        .Font.Bold = True
                        .Font.ColorIndex = 1
                   End With
         
        Cells(i + 3, col_header + 18).Value = "Group3"
                     With Cells(i + 3, col_header + 18)
                        .Font.Bold = True
                        .Font.ColorIndex = 1
                   End With
         
         
          Cells(i + 4, col7 + 11).Value = "Model"
                    With Cells(i + 4, col7 + 11)
                        .Font.Bold = True
                        .Font.ColorIndex = 1
                   End With
         
         
          Cells(i + 4, col7 + 12).Value = "Act"
                    With Cells(i + 4, col7 + 12)
                        .Font.Bold = True
                             .Font.ColorIndex = 1
                   End With

         
          Cells(i + 4, col7 + 13).Value = "Var"
                    With Cells(i + 4, col7 + 13)
                        .Font.Bold = True
                        .Font.ColorIndex = 1
                   End With
         
       
         
                   
  Range("A" & i + 4, "Y" & i + 4).Select
         
             With Selection.Borders(xlEdgeBottom)
                  .LineStyle = xlContinuous
                  .Weight = xlMedium
                  .ColorIndex = 1
             End With
         
         
         
          Application.ScreenUpdating = True
            Application.Calculation = xlCalculationAutomatic
        Exit Sub
    End If
Next i

End Sub
-------------------------------------------------------------------------------------------------------------------


The problem is that the borders are dependent on how much data is in Model.

 
Related Solutions
Keywords: add ing borders using vba
 
Loading Advertisement...
 
[+][-]01/29/08 09:56 PM, ID: 20774971Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/30/08 01:33 AM, ID: 20775760Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/30/08 11:11 PM, ID: 20784555Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/31/08 01:45 AM, ID: 20785151Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/31/08 09:34 PM, ID: 20794441Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: VB Script
Sign Up Now!
Solution Provided By: weellio
Participating Experts: 1
Solution Grade: A
 
 
Loading Advertisement...
20091111-EE-VQP-89 / EE_QW_2_20070628