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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
FoundCell will only be a single cell. Try

Rich (BB code):
Dim FoundCell As Range
Set FoundCell = .Find(what:=cbCust.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If Not FoundCell Is Nothing Then MsgBox FoundCell.Address(False, False)
 

Dr.Evil925

New Member
Joined
Feb 24, 2011
Messages
22
ok

So how can i get the cell reference?
Or if it had an actual range how could i get the info?
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
You could assign it to a variable

Code:
Dim FoundCell As Range, s As String
Set FoundCell = .Find(what:=cbCust.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If Not FoundCell Is Nothing Then s = FoundCell.Address(False, False)

But why not just use FoundCell directly?
 

Dr.Evil925

New Member
Joined
Feb 24, 2011
Messages
22

ADVERTISEMENT

I have a row of "customers" and under each of them is a list of names. I am trying to find the first open cell under the customer picked by a combobox so i can add a new name to the list.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try like this

Code:
Dim FoundCell As Range, s As String
Set FoundCell = .Find(what:=cbCust.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If Not FoundCell Is Nothing Then FoundCell.Offset(1).Value = "New Customer"
 

Dr.Evil925

New Member
Joined
Feb 24, 2011
Messages
22

ADVERTISEMENT

That works for the first name but if I have 2 or 3 names in the list already?
How can i get it to insert into an open cell, which might be row 2,3,4...?
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try like this

Code:
Range("A" & Rows.Count).End(xlUp).Offset(1).Value = "New Customer"
 

Dr.Evil925

New Member
Joined
Feb 24, 2011
Messages
22
Code:
Range("A" & Rows.Count).End(xlUp).Offset(1).Value = "New Customer"
:confused:maybe I am blind, but where would i put this.
after "If Not FoundCell Is Nothing Then" and change "A" to FoundCell"?
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
It isn't clear what you are trying to do. The last bit of code that I posted will add a value in the next empty row in column A.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,598
Messages
5,832,643
Members
430,150
Latest member
amitk1

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
Top