Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Loop thru named range of second sheet

I have a workbook with 2 sheets in it

On sheet one, I have a layout of fields (range A1 though M20). Cell A1 has
a value in it, and all of the other cells obtain their values using a vlookup
into a named range on sheet two based upon the value in Cell A1 of sheet one.

I need to create a button that will ascertain a value from the user, using a
dropdown, then loop through the named range on sheet two, looking at the
values in column 1. Wherever it finds a match, it needs to pick off the
value of column 2 of the named range, place that value in cell A1 of sheet
one, thus causing all the other values to be filled in via their vlookup
formulas, and then print Range A1 through M20 of sheet one.

I am successfully doing everything except I cannot figure out how to
reference the cells in the named range of sheet two. I need to know what to
put within my double brackets below:

Dim i as integer
Dim strArgValue as string
strArgValue = Cells(23, 1) 'pick up the value from the dropdown
For i = 1 to [[the number of rows in the named range on sheet two]]
If [[col 1 of row i of the named range of sheet two]] = strArgValue then
Cells(1, 1) = [[the value in col 2 of row i of the named range of
sheet two]]
.....Do other processing, including printing the desired range
End If
i = i + 1
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Loop thru named range of second sheet

Try SheetName.Range("i1").Value

"Bill Sturdevant" wrote:

I have a workbook with 2 sheets in it

On sheet one, I have a layout of fields (range A1 though M20). Cell A1 has
a value in it, and all of the other cells obtain their values using a vlookup
into a named range on sheet two based upon the value in Cell A1 of sheet one.

I need to create a button that will ascertain a value from the user, using a
dropdown, then loop through the named range on sheet two, looking at the
values in column 1. Wherever it finds a match, it needs to pick off the
value of column 2 of the named range, place that value in cell A1 of sheet
one, thus causing all the other values to be filled in via their vlookup
formulas, and then print Range A1 through M20 of sheet one.

I am successfully doing everything except I cannot figure out how to
reference the cells in the named range of sheet two. I need to know what to
put within my double brackets below:

Dim i as integer
Dim strArgValue as string
strArgValue = Cells(23, 1) 'pick up the value from the dropdown
For i = 1 to [[the number of rows in the named range on sheet two]]
If [[col 1 of row i of the named range of sheet two]] = strArgValue then
Cells(1, 1) = [[the value in col 2 of row i of the named range of
sheet two]]
.....Do other processing, including printing the desired range
End If
i = i + 1
Next

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Loop thru named range of second sheet

Dim i as integer
Dim strArgValue as string
strArgValue = Cells(23, 1) 'pick up the value from the dropdown
For i = 1 to Worksheets("Sheet2").Range("myRange").Rows.Count
If Worksheets("Sheet2").Range("myRange").Cells(i,1) = strArgValue then
Cells(1, 1) = Worksheets("Sheet2").Range("myRange").Cell(i,2).Va lue
.....Do other processing, including printing the desired range
End If
i = i + 1
Next

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill Sturdevant" wrote in
message ...
I have a workbook with 2 sheets in it

On sheet one, I have a layout of fields (range A1 though M20). Cell A1

has
a value in it, and all of the other cells obtain their values using a

vlookup
into a named range on sheet two based upon the value in Cell A1 of sheet

one.

I need to create a button that will ascertain a value from the user, using

a
dropdown, then loop through the named range on sheet two, looking at the
values in column 1. Wherever it finds a match, it needs to pick off the
value of column 2 of the named range, place that value in cell A1 of sheet
one, thus causing all the other values to be filled in via their vlookup
formulas, and then print Range A1 through M20 of sheet one.

I am successfully doing everything except I cannot figure out how to
reference the cells in the named range of sheet two. I need to know what

to
put within my double brackets below:

Dim i as integer
Dim strArgValue as string
strArgValue = Cells(23, 1) 'pick up the value from the dropdown
For i = 1 to [[the number of rows in the named range on sheet two]]
If [[col 1 of row i of the named range of sheet two]] = strArgValue

then
Cells(1, 1) = [[the value in col 2 of row i of the named range of
sheet two]]
.....Do other processing, including printing the desired range
End If
i = i + 1
Next



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Loop thru named range of second sheet

Range("Dog")

will refer to the named range regardless of which sheet it is on if it is a
workbook level name and there are no sheet level ranges named dog
(Sheet1!Dog for example)

Dim rng as Range, i as Long

For i = 1 to Worksheets("Sheet2").Range("Dog").Rows.count
set rng = worksheets("Sheet2").Cells(i,1)
if rng.Value = strArgValue then
cells(1,1).Value = rng.offset(0,1).Value
end if
Next

You don't need i = i + 1 since the loop increments i

--
Regards,
Tom Ogilvy


"Bill Sturdevant" wrote in
message ...
I have a workbook with 2 sheets in it

On sheet one, I have a layout of fields (range A1 though M20). Cell A1

has
a value in it, and all of the other cells obtain their values using a

vlookup
into a named range on sheet two based upon the value in Cell A1 of sheet

one.

I need to create a button that will ascertain a value from the user, using

a
dropdown, then loop through the named range on sheet two, looking at the
values in column 1. Wherever it finds a match, it needs to pick off the
value of column 2 of the named range, place that value in cell A1 of sheet
one, thus causing all the other values to be filled in via their vlookup
formulas, and then print Range A1 through M20 of sheet one.

I am successfully doing everything except I cannot figure out how to
reference the cells in the named range of sheet two. I need to know what

to
put within my double brackets below:

Dim i as integer
Dim strArgValue as string
strArgValue = Cells(23, 1) 'pick up the value from the dropdown
For i = 1 to [[the number of rows in the named range on sheet two]]
If [[col 1 of row i of the named range of sheet two]] = strArgValue

then
Cells(1, 1) = [[the value in col 2 of row i of the named range of
sheet two]]
.....Do other processing, including printing the desired range
End If
i = i + 1
Next



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Referencing a named range on another sheet Jan B Excel Worksheet Functions 5 April 4th 23 12:38 PM
Refer to Named Range on another sheet for IF function David Excel Worksheet Functions 3 August 26th 06 04:12 AM
plz help: creating named range in VBA, loop goes haywire KR Excel Programming 2 April 14th 05 07:25 PM
create named range in each sheet in workbook davegb Excel Programming 3 March 29th 05 07:47 PM
Referencing Named Range in Other Sheet Dan E[_2_] Excel Programming 0 July 11th 03 04:22 PM


All times are GMT +1. The time now is 09:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"