View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Beginner question about selecting a range

Range(StartCell).Resize(NumRows,NumColumns).Select

as for your goal:
Range(StartCell).CurrentRegion.Select

Also
Using the refedit control allows the user to select the range using the
mouse.

--
Regards,
Tom Ogilvy

"TBA" wrote in message
...
Greetings!

I am in the process of teaching myself VBA using Excel 97. The logic of
coding doesn't bother me, but the syntax is another story.

Let me present a simplified example of a coding effort. I'm trying to get
Excel to select a range based on some user inputs.

Private Sub cmd1_form1_Click()

Dim StartCell As String `Maybe a different variable type here?
Dim NumColumns As Integer
Dim NumRows As Integer

StartCell = txt1_form1.Text
NumColumns = txt2_form1.Text
NumRows = txt3_form1.Text

` txt4_form1.Text = StartCell & " " & NumColumns & " " _
NumRows

Range(?????).Select 'This is what I'm after

End Sub

I did the easy part and built the form for entering these values, and I

can
display the entered values in a fourth text box, but what I really want to
do is select the range specified by these user entered values, i.e. if the
user enters A1,4,6 then I want Excel to select the range A1:D6.

I'm somewhat familiar with the Range(argument).Select function, but I

can't
figure out how to perform the necessary calculations on the initial cell
reference entered by the user.

I'm thinking I may need to make better choices for the value types entered
by the user (maybe string, integer, integer are not good choices).

Could anyone post a simple block of code that will perform the example I
described above?

This is a simple example to help me get comfortable conceptually. My true
mini-goal is to merely have the user specify a starting cell and then have
the code determine the extents of a table already present on a worksheet.

Any tips or suggestions greatly appreciated - TIA!

-gk-