If Exists Name Function VBA

saschmeling

New Member
Joined
Jun 27, 2012
Messages
39
Hi,

I have a VBA program that creates a report sheet using information from other sheets. This is done monthly. I would like to format the section total rows if they exist. Here is what is going on.

The report pulls information from one workbook, and assigns names to a total row if said total row exists. Such as CapitalExpense. Capital Expenses may not exist every month, the name is created only if the section exists. This is done for 8 separate sections. Now I would like to go back and add a thick bottom border to those rows only if those rows exist.

Here is the step process for each one.

If Name Exists- select name cell
Expand selection to include 4 columns to the right of the named cell.
Add a thick bottom border to selection.
Next Name in array.

Please help if you have any suggestions.

Thanks,
Scott
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi

You can use this procedure
Code:
Option Explicit


Sub BorderRangeName()
  Dim NameRange As String


  NameRange = "CapitalExpense"


    If IsRangeName(NameRange) Then
        With Range(NameRange).Resize(, 4)
            With .Borders()
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = xlAutomatic
            End With
        End With
    End If
    
End Sub




Public Function IsRangeName(rangeName As String) As Boolean
    On Error Resume Next
    IsRangeName = Len(Names(rangeName).Name) <> 0
End Function
Mytå
 
Last edited:
Upvote 0
Re

An other suggestion
Code:
Option Explicit


Sub BorderRangeName()
    Dim NameRange As String


    NameRange = "CapitalExpense"


    If IsRangeName(NameRange) Then
        ActiveWorkbook.Names.Add _
                Name:=NameRange, RefersTo:=Range(NameRange).Resize(, 4)
        Range(NameRange).BorderAround Weight:=xlThin
    End If


End Sub




Public Function IsRangeName(rangeName As String) As Boolean
    On Error Resume Next
    IsRangeName = Len(Names(rangeName).Name) <> 0
End Function
Mytå
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,348
Members
452,638
Latest member
Oluwabukunmi

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