combobox list of sheet2

  • Thread starter tkraju via OfficeKB.com
  • Start date
T

tkraju via OfficeKB.com

this code is giving active sheet list.
LastRow = Range("H3").End(xlDown).Row
myList = Range(Cells(3, 8), Cells(LastRow, 14)).Address
what change is to be done to the above code if I want "sheet2 " list with
same parameters of above code.
 
J

joel

Use Address with external = true. this gives the workbook as well so I added
code to remove the workbook.

LastRow = Range("H3").End(xlDown).Row
MyList = Range(Cells(3, 8), Cells(LastRow, 14)).Address(external:=True)
'remove workbook
MyList = Mid(MyList, InStr(MyList, "]") + 1)
 
P

Patrick Molloy

with worksheets("sheet2")
LastRow = .Range("H3").End(xlDown).Row
myList = .Range(.Cells(3, 8), .Cells(LastRow, 14)).Address
end with

fyi
this is the same as

LastRow = worksheets("sheet2").Range("H3").End(xlDown).Row
myList = worksheets("sheet2").Range(.Cells(3, 8),
worksheets("sheet2").Cells(LastRow, 14)).Address

but from a code perspective, its much cleaner IMHO
:)
 
D

Dave Peterson

Dim myList as string
Dim LastRow as string

With worksheets("Sheet2")
lastrow = .range("H3").end(xldown).row
mylist = .range("H3:H" & lastrow).address(external:=true)
end with

I'd leave the workbook name, worksheet name, and address in that string. It
won't ever hurt and without it, you may have trouble.
 
T

tkraju via OfficeKB.com

Thank you,joel.its great,worked perfectly.
Use Address with external = true. this gives the workbook as well so I added
code to remove the workbook.

LastRow = Range("H3").End(xlDown).Row
MyList = Range(Cells(3, 8), Cells(LastRow, 14)).Address(external:=True)
'remove workbook
MyList = Mid(MyList, InStr(MyList, "]") + 1)
this code is giving active sheet list.
LastRow = Range("H3").End(xlDown).Row
myList = Range(Cells(3, 8), Cells(LastRow, 14)).Address
what change is to be done to the above code if I want "sheet2 " list with
same parameters of above code.
 
T

tkraju via OfficeKB.com

Thank you Dave.perfectly worked.

Dave said:
Dim myList as string
Dim LastRow as string

With worksheets("Sheet2")
lastrow = .range("H3").end(xldown).row
mylist = .range("H3:H" & lastrow).address(external:=true)
end with

I'd leave the workbook name, worksheet name, and address in that string. It
won't ever hurt and without it, you may have trouble.
this code is giving active sheet list.
LastRow = Range("H3").End(xlDown).Row
[quoted text clipped - 5 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top