Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function "Range" code syntax problem 1

Status
Not open for further replies.

mscallisto

Technical User
Jun 14, 2001
2,990
US
Code:
Dim usedrowsCol_T as integer
usedrowsCol_T = Cells(Cells.Rows.Count, "T").End(xlUp).Row
Set Company = Worksheets("calls").Range("S2:T25")

In the above code I want to change the hardcoded T25 to say T and the last row used in col T

Set Company = Worksheets("calls").Range(" 'S2:T' & string(usedrowsCol_T)")

My syntax needs help
 

Hi,
Code:
Dim usedrowsCol_T as integer
usedrowsCol_T = Cells(Cells.Rows.Count, "T").End(xlUp).Row
Set Company = Worksheets("calls").Range("S2:T" & usedrowsCol_T )



[tt][highlight blue][white]
~ ~
[/white][/highlight][highlight red][white] To be ~[/white][/highlight][highlight blue][white]
~ BE ~
[/white][/highlight][highlight white][blue] safe on the 4th ~[/blue][/highlight][highlight blue][white]
~ ADVISED ~
[/white][/highlight][highlight red][white] Don't ~[/white][/highlight][highlight blue][white]
~ ~
[/white][/highlight][highlight white][blue] get a ~[/blue][/highlight]
[highlight red][white] 5th on the 3rd ~[/white][/highlight]
[highlight white][blue] Or you might not ~[/blue][/highlight]
[highlight red][white] Come 4th on the 5th 4thwith ~[/white][/highlight]


[/tt]

Skip,

[glasses] [red][/red]
[tongue]
 
Perhaps this ?
Set Company = Worksheets("calls").Range("S2:T" & usedrowsCol_T)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hmm, are all the ranges on that sheet?

..

Code:
With Worksheets("calls")
    Set Company = .Range("S2:T" & .Cells(.cells.rows.count, "T").end(xlup).row))
End With

-----------
Regards,
Zack Barresse
 
Thanks Skip

"Logic is easy Syntax is @^%$#!!!".....I swear I tried that.


and thanks Zack, I usually like less lines of code but in this case I have many columns that I need the row count for so I grouped the row count logic up front for documentation.
 


Zack had a very valid point.

You will run into problems if the activeSheet is NOT calls.

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top