Named Range Info Help

Dr.Evil925

New Member
Joined
Feb 24, 2011
Messages
22
I have a macro that sets a range named FoundCell.
Code:
Dim FoundCell As Range
Set FoundCell = .Find(what:=cbCust.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=faulse)
How can i access the cell locations in it so i can change them, or reference them later in my code?

example
if "FoundCell" is range A1:A5 how can i see that info first, second how can i change that to A1:A10?:confused:

Thanks in advance.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Maybe this:
Code:
Dim FoundCell As Range, s As String
Set FoundCell = Cells.Find(what:=cbCust.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If Not FoundCell Is Nothing Then
    If Not IsEmpty(FoundCell.Offset(1)) Then
        FoundCell.End(xlDown).Offset(1).Value = "NewCustomer"
    Else
        FoundCell.Offset(1).Value = "NewCustomer"
    End If
End If
 
Upvote 0
JoeMo
This looked like it would work but when i put it in i get a "Application-defined or object-defined error" on the "then" statement.
Code:
Dim FoundCell As Range
Application.ScreenUpdating = False
   With Worksheets("Account DB")
       With .Rows(1)
        Set FoundCell = .Find(what:=cbCust.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=faulse)
        If Not FoundCell Is Nothing Then
        FoundCell.End(xlDown).Offset(1).Value = "New Customer"
        Else
        FoundCell.Offset(1).Value = "NewCustomer"
        End If
        End With

    End With
 
Upvote 0
Dont know what happened, something must have not copied over. I retyped the line and it works now.

:)Thanks JoeMo, and VoG
 
Upvote 0
OK found a problem. I get "Application-defined or object-defined error" when i dont have anything under "FoundCell" or rows 2,3,4... if i have something in row 2 then it works right.
 
Upvote 0
The problem was on my end.:(
Here is my finished code. I am open to any suggestions, but as it is now it works as i want it to.

Thanks for all your help.
Code:
Dim FoundCell As Range
Dim FoundName As Range
Application.ScreenUpdating = False
   With Worksheets("Account DB")
       With .Rows(1)
        Set FoundCell = .Find(what:=cbCust.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=faulse)
            With FoundCell.EntireColumn
                Set FoundName = .Find(what:=cbName.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=faulse)
                If FoundName Is Nothing Then
                    If Not IsEmpty(FoundCell.Offset(1)) Then
                    FoundCell.End(xlDown).Offset(1).Value = cbName.Value
                    Else
                    FoundCell.Offset(1).Value = cbName.Value
                    End If
                MsgBox "Added " & cbName.Value & "!"
                Else
                MsgBox cbName.Value & " already exists"
                End If
            End With
        End With
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,234
Messages
6,123,773
Members
449,123
Latest member
StorageQueen24

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