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.
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

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.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,501
Messages
5,523,292
Members
409,508
Latest member
Afc

This Week's Hot Topics

Top