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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to activate any cell in the worksheet?

Status
Not open for further replies.

ljCharlie

IS-IT--Management
Apr 21, 2003
397
US
Is there a way to activate any cell and make it active in the worksheet at anytime in the program?


Any help is appreciated.

ljCharlie
 
I have tried the following:

Function numbCols(countrows) As Integer
Dim shtAnnual As Worksheet
Dim rng As Range
Dim numCols As Integer
Dim txtInbox As String

Set shtAnnual = ActiveSheet
'activate the first cell as a starting point for counting non-empty rows
shtAnnual.Cells(1, 1).Activate

Set rng = ActiveCell

'Loop until an empty cell is found.
Do While rng.Value <> ""
numCols = numCols + 1
Set rng = rng.Offset(0, 1)
Loop
numbCols = numCols
shtAnnual.Cells(0, 15).Activate
Set rng = ActiveCell
txtInbox = InputBox("Result Column", "Parse Result", "Please enter what column name you want for the result column")
rng.Cells = txtInbox
End Function

The error I got is: Application-defined or object-defined error on this line: shtAnnual.Cells(0, 15).Activate

Is it because I have activated twice in the same function?

ljCharlie
 

The lowest row number for the .Cells property is 1.

Perhaps you mean to say
[tt]
shtAnnual.Cells(1, 16).Activate
[/tt]

It can be confusing, because .Offset can begin with (0,0).

 
Thanks! You're right.I got confuse because offset uses 0 but cell uses 1. It works!

ljCharlie
 


FYI,

There is usually no need to use the Activate and Select methods in VB code unlesws you want a particular sheet/cell to be selected when the code ends. Excessive use of Activate & Select, slow code execution.

How Can I Make My Code Run Faster? faq707-4105

Skip,
[sub]
[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top