• Excel Macro (Excel XP)

    Author
    Topic
    #411800

    I have 6 spreadsheets with all the same information (campus specific). What I would like to do is in a column that corresponds with the campus create “boxes” with borders. I’m not quite sure how to write the code. Can some savy VB expert help me?

    Thanks

    Racheal

    Viewing 4 reply threads
    Author
    Replies
    • #895366

      I’m not sure exactly what you want to do. The code in This Post shows how to put a border around a cell.

    • #895578

      (Edited by HansV – inserted

       and 

      tags to preserve spacing – see Help 19)

      PHI	120						
      		Community	 	X	 	 	
      		Desert Vista	 	X	 	 	
      		Downtown	X	X	X	 	
      		East	 	 	 	X	
      		Northwest	 	 	 	X	
      		West	X	X	X	 	
      PHI	122						
      		Community	 	 	 	X	
      		Desert Vista	X	X	X	 	
      		Downtown	X	 	 	 	
      		East	 	 	 	X	
      		Northwest	 	 	 	X	
      		West	 	X	 	 	
      PHI	123						
      		Community	 	 	 	X	
      		Desert Vista	X	X	X	 	
      		Downtown	 	 	 	X	
      		East	 	 	 	X	
      		Northwest	 	 	 	X	
      		West	X	X	 	 	
      

      Above is part of the spread sheet layout

      Where it has the specific campuses I wanted to create “boxes” on that campus line but in another set of columns. I hope this clarifies better what I want

      Thanks for any and all of your help.

      Racheal

      • #895607

        It is not clear to me what you want. Could you elaborate some more?

        What do you mean by “boxes”?
        Steve

      • #895608

        It is not clear to me what you want. Could you elaborate some more?

        What do you mean by “boxes”?
        Steve

      • #895609

        First, it would be much easier if you would upload a workbook with the data in it. That way we could see what actual columns and rows the data is actually in and we could use that to test the VBA code to do what you are asking.

        What you are asking is still not very clear. What is a “campus?” Is it PHI or 120 or Community. I would guess that it is Community which I would guess is in Column C, but could be column B or D or E or … What other “set of columns” do you want boxes? The columns with the X’s in them? If so, do you want boxes around all of the columns with X;s in them? What columns are the X’s in? If not the columns with the X’s, then what columns? Is it OK to make the “boxes” by putting borders around the cells, or are you looking for something else. Could you define what a box is?

      • #895610

        First, it would be much easier if you would upload a workbook with the data in it. That way we could see what actual columns and rows the data is actually in and we could use that to test the VBA code to do what you are asking.

        What you are asking is still not very clear. What is a “campus?” Is it PHI or 120 or Community. I would guess that it is Community which I would guess is in Column C, but could be column B or D or E or … What other “set of columns” do you want boxes? The columns with the X’s in them? If so, do you want boxes around all of the columns with X;s in them? What columns are the X’s in? If not the columns with the X’s, then what columns? Is it OK to make the “boxes” by putting borders around the cells, or are you looking for something else. Could you define what a box is?

    • #895611

      Attached is a sample of the worksheet and a comment explaining what I want to do.

      Racheal

      • #895623

        Still not entirely clear.
        Try a guess: Would cond formatting work?

        Select (eg) D4: G whatever
        Format – cells – Border(tab) -none
        Format – conditional formatting
        select from list: FormulaIs
        Enter the formula:
        =$C4″”

        Border(tab) – press “solid line” and “outline” button

        Steve

        • #895651

          I probably followed your directions incorrectly as it did nothing.
          Racheal

          • #895655

            What do you mean by “nothing”

            It should pull up several dialog boxes at least
            Dialog1(Formatting)
            Initially it will”clear” the borders
            dialog2 (cond formatting)
            Then it will add borders around the cells that selected that have something in Cell C4

            What step fails?

            Steve

            • #895657

              I selected the cell that I wanted with the borders and followed your steps. After I hit ok the cell still didn’t have borders. If there has to be text in the cell then it will not work for what I want. Thanks
              Racheal

            • #895688

              There just has to be text in column C of that row to add the borders.

              Could you attach the demo sheet where you followed the directions?
              Steve

            • #895692

              I will try it again but I will put a header on the column. If that doesn’t work then I will forward you a copy.
              Thanks again
              Racheal

            • #895693

              I will try it again but I will put a header on the column. If that doesn’t work then I will forward you a copy.
              Thanks again
              Racheal

            • #895689

              There just has to be text in column C of that row to add the borders.

              Could you attach the demo sheet where you followed the directions?
              Steve

            • #895658

              I selected the cell that I wanted with the borders and followed your steps. After I hit ok the cell still didn’t have borders. If there has to be text in the cell then it will not work for what I want. Thanks
              Racheal

          • #895656

            What do you mean by “nothing”

            It should pull up several dialog boxes at least
            Dialog1(Formatting)
            Initially it will”clear” the borders
            dialog2 (cond formatting)
            Then it will add borders around the cells that selected that have something in Cell C4

            What step fails?

            Steve

        • #895652

          I probably followed your directions incorrectly as it did nothing.
          Racheal

      • #895624

        Still not entirely clear.
        Try a guess: Would cond formatting work?

        Select (eg) D4: G whatever
        Format – cells – Border(tab) -none
        Format – conditional formatting
        select from list: FormulaIs
        Enter the formula:
        =$C4″”

        Border(tab) – press “solid line” and “outline” button

        Steve

      • #895631

        See if this does what you want:

        Public Sub InsertBorders()
        Dim I As Long, lLastRow As Long
            With Worksheets("Sheet1")
                lLastRow = .Range("C65536").End(xlUp).Row - 1
                For I = 3 To lLastRow
                    If .Range("C1").Offset(I, 0).Value  "" Then
                        With .Range("D1:G1").Offset(I, 0).Borders
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                    End If
                Next I
            End With
        End Sub
        
        • #895643

          Did it work for you?
          I tried to cut and past the code but it’s not working

          Racheal

          • #895716

            I think I still did not understand what you wanted. I was putting borders around the cells in columns D:G. Looking at it again, I think you wanted the borders around the cells in I:L. Try the code below. If you want to put borders around both sets of columns, then uncomment the commented code.

            Public Sub InsertBorders()
            Dim I As Long, lLastRow As Long
                With Worksheets("Sheet1")
                    lLastRow = .Range("C65536").End(xlUp).Row - 1
                    For I = 3 To lLastRow
                        If .Range("C1").Offset(I, 0).Value  "" Then
            '                With .Range("D1:G1").Offset(I, 0).Borders
            '                    .LineStyle = xlContinuous
            '                    .Weight = xlThin
            '                    .ColorIndex = xlAutomatic
            '                End With
                            With .Range("I1:L1").Offset(I, 0).Borders
                                .LineStyle = xlContinuous
                                .Weight = xlThin
                                .ColorIndex = xlAutomatic
                            End With
                        End If
                    Next I
                End With
            End Sub
            
          • #895717

            I think I still did not understand what you wanted. I was putting borders around the cells in columns D:G. Looking at it again, I think you wanted the borders around the cells in I:L. Try the code below. If you want to put borders around both sets of columns, then uncomment the commented code.

            Public Sub InsertBorders()
            Dim I As Long, lLastRow As Long
                With Worksheets("Sheet1")
                    lLastRow = .Range("C65536").End(xlUp).Row - 1
                    For I = 3 To lLastRow
                        If .Range("C1").Offset(I, 0).Value  "" Then
            '                With .Range("D1:G1").Offset(I, 0).Borders
            '                    .LineStyle = xlContinuous
            '                    .Weight = xlThin
            '                    .ColorIndex = xlAutomatic
            '                End With
                            With .Range("I1:L1").Offset(I, 0).Borders
                                .LineStyle = xlContinuous
                                .Weight = xlThin
                                .ColorIndex = xlAutomatic
                            End With
                        End If
                    Next I
                End With
            End Sub
            
        • #895644

          Did it work for you?
          I tried to cut and past the code but it’s not working

          Racheal

      • #895632

        See if this does what you want:

        Public Sub InsertBorders()
        Dim I As Long, lLastRow As Long
            With Worksheets("Sheet1")
                lLastRow = .Range("C65536").End(xlUp).Row - 1
                For I = 3 To lLastRow
                    If .Range("C1").Offset(I, 0).Value  "" Then
                        With .Range("D1:G1").Offset(I, 0).Borders
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                    End If
                Next I
            End With
        End Sub
        
    • #895612

      Attached is a sample of the worksheet and a comment explaining what I want to do.

      Racheal

    • #895431

      Many people know you can group sheets by control or shift-clicking their tabs and that after doing that any (formatting) change made to the active sheet are reflected to all grouped sheets.

      Very few people know you can do the same for multiple workbooks too.

      – Insert a blank workbook, open the VBE (alt-F11) and paste in this code:

      Sub groupworkbooks()
      Application.Dialogs(xlDialogWorkgroup).Show
      End Sub

      Now exit the VBE.

      – Open all files you need to group
      – now hit alt-F8 and run the macro called Groupworkbooks
      – select the sheets in the list you wish to group and hit OK (by default all sheets are selected, unselect the ones you wish NOT to group)
      – You will see [Group] appear in the title bar.

      Start modifying your sheet.

      Note: As soon as you change to another worksheet or workbook, the grouping is cancelled.

      • #900230

        Nifty!
        And is this only available through the VBE?

        • #900515

          Yes, I haven’t been able to do it otherwise.

          • #900619

            It makes you wonder what other Dialogs and functionality is hidden deep in the recesses of VBA???
            I should have a closer look at the Dialogs() feature!

            • #900649

              Good luck, there’s 240 of them in Excel XP….

            • #900669

              I’ll scan through those I don’t recognise! As most are common in the menus

            • #900670

              I’ll scan through those I don’t recognise! As most are common in the menus

            • #900650

              Good luck, there’s 240 of them in Excel XP….

          • #900620

            It makes you wonder what other Dialogs and functionality is hidden deep in the recesses of VBA???
            I should have a closer look at the Dialogs() feature!

          • #966596

            I’d like to control this grouping function without showing the dialog box. I already know what files I’d like to group.
            Any suggestions?

            • #966618

              Jan Karel is not available at the moment.

              As far as I know, the dialog is the only way the workbook grouping feature is exposed. If you want to group ALL workbooks/worksheets, you can use

              Sub GroupAll()
              SendKeys “~”
              Application.Dialogs(xlDialogWorkgroup).Show
              End Sub

            • #968357

              Hi Catherine,

              I could not find a way to do this, apart from using the dialog.

        • #900516

          Yes, I haven’t been able to do it otherwise.

      • #900231

        Nifty!
        And is this only available through the VBE?

      • #903942

        Jan Karel:

        Thanks for that – very useful.

        Do you have any other similar hidden gems?

        Tony.

      • #903943

        Jan Karel:

        Thanks for that – very useful.

        Do you have any other similar hidden gems?

        Tony.

    Viewing 4 reply threads
    Reply To: Reply #895643 in Excel Macro (Excel XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel