Code Modification

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Range(numcount1 + 2 & ":" & numcount2).Select

The above codes selects a range of cells. I am trying to
get it to stop selection at column K. Below is what I am
trying to do but it is not working. How do I get it to
select only through column K? When I run this code I get
the error "Method 'Range' of object'_Worksheet'failed"

Range(numcount1 + 2 & ":K" & numcount2).Select

Thank you
Todd Huttenstine
 
Are you looking to start at column A? Try:

Range("A" & numcount1 + 2 & ":K" & numcount2).Select
 
Thats not working. The K is messing it up. By the way,
the variable numcount1 + 2 is a valid cell number so that
already works. Below is how numcount2 is derived:

numcount2 = Application.WorksheetFunction.Count(Worksheets
(1).Columns("B:B")) + 1

Now, Worksheets(1).Range(numcount1 + 2 & ":" &
numcount2).Select works but the only problem is that the
selection never stops going right to left. The selection
continues to the end of the sheet. I cant have this
because the next line of the code is
Selection.ClearContents and when ran it will delete more
data than I want. To correct this I need to add that K so
the selection has an ending point. Even when I define
numcount2 as numcount2 = "K" &
Application.WorksheetFunction.Count(Worksheets(1).Columns
("B:B")) + 1 (adding the K when I define the variable
instead of adding it before the variable) and keep the
Worksheets(1).Range(numcount1 + 2 & ":" &
numcount2).Select the same, it still fails. I think it
has to be a syntax problem or something. Any suggestions?

Thanx

Todd Huttenstine
 
Is numcount1 an integer? Or is it a cell address?

Also, do you want the selection so start at A and go to K, or start at K and
go to IV?
 
numcount1 is a variant as well as my other variables used
in this procedure. In this case numcount1 is equal to 8
and numcount2 is 72. The range will start in A and end at
K. Because the code adds 2 to numcount1 the range is
A10:72 however I want to add the K so it goes through
A10:K72.
 
In that case, the code I gave you should have definitely worked. Try it
again and check for typos:

Range("A" & numcount1 + 2 & ":K" & numcount2).Select
 
Ahh that worked! thanx
-----Original Message-----
In that case, the code I gave you should have definitely worked. Try it
again and check for typos:

Range("A" & numcount1 + 2 & ":K" & numcount2).Select

--

Vasant






.
 

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

Back
Top