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?
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] [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! [/sub]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.