Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / December 2005

Tip: Looking for answers? Try searching our database.

User form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Rogers - 15 Dec 2005 06:10 GMT
Hi All:

Would it be better to use code with a msg box to enter data into a range of
cells or would a UserForm be better?  Is it possible to use a UserForm to
place data in only a range of cells?  If that can be done can it place the
data in the selected cell within that range?

Mike Rogers
Dave Peterson - 15 Dec 2005 19:11 GMT
You mean inputbox?

If you have lots of data to retrieve all at once, a userform seems better to me.

If it's just one per row, maybe inputbox would suffice.

Debra Dalgleish has some getstarted notes at:
http://contextures.com/xlUserForm01.html

> Hi All:
>
[quoted text clipped - 4 lines]
>
> Mike Rogers

Signature

Dave Peterson

Mike Rogers - 15 Dec 2005 23:38 GMT
Dave,

Yes an input box!  I am trying to input information into a range of cells
that I can have locked.  Thereby disallowing anyone from copy and pasting the
information in one cell to another.  Would the input box be called by
selecting a cell in the desired range? Or would it be called by a command
button?

> You mean inputbox?
>
[quoted text clipped - 13 lines]
> >
> > Mike Rogers
Dave Peterson - 15 Dec 2005 23:52 GMT
Either way is ok with me.

If you want it based on selecting a cell, you could use a worksheet event:

Rightclick on the worksheet tab that should have the behavior.  Select view
code.  Paste this in:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Target.Cells.Count > 1 Then Exit Sub
   If Intersect(Target, Me.Range("a2:a99")) Is Nothing Then
       Exit Sub
   End If
   
   UserForm1.Show
   
End Sub

You'll have to adjust the range and the userform name.

Or something like this to use an inputbox:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

   Dim myStr As String
   
   If Target.Cells.Count > 1 Then Exit Sub
   If Intersect(Target, Me.Range("a2:a99")) Is Nothing Then
       Exit Sub
   End If
   
   myStr = InputBox(Prompt:="what do you want to enter in " _
                        & Target.Address(0, 0) & "?")
   
   If Trim(myStr) = "" Then
       'do nothing
   Else
       Me.Unprotect Password:="hi"
       Application.EnableEvents = False
       Target.Value = myStr
       Application.EnableEvents = True
       Me.Protect Password:="hi"
   End If
   
End Sub

> Dave,
>
[quoted text clipped - 25 lines]
> >
> > Dave Peterson

Signature

Dave Peterson

Mike Rogers - 16 Dec 2005 00:16 GMT
Dave

Wow thanks for the complete response!!!!  I really do appreiciate it.  I
think the simplest solution is the imput box.  But I have a problem with
either way..... I already have a Private Sub Worksheet_SelectionChange(ByVal
Target As Range) procedure in place and, as little as I know, I know two of
them will not work well together.  What changes would I need to make in the
input box code to call it from a command button, if that will work at all???
and then place the data in the active cell.  
Thanks again

Mike Rogers

> Either way is ok with me.
>
[quoted text clipped - 72 lines]
> > >
> > > Dave Peterson
Dave Peterson - 16 Dec 2005 02:06 GMT
You'll have to combine them:

For instance:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

   Dim myStr As String
   
   If Target.Cells.Count > 1 Then Exit Sub
   If Not (Intersect(Target, Me.Range("a2:a99")) Is Nothing) Then
       myStr = InputBox(Prompt:="what do you want to enter in " _
                        & Target.Address(0, 0) & "?")
       
       If Trim(myStr) = "" Then
           'do nothing
       Else
           Me.Unprotect Password:="hi"
           Application.EnableEvents = False
           Target.Value = myStr
           Application.EnableEvents = True
           Me.Protect Password:="hi"
       End If
   End If
   
   'your other code
       
End Sub

> Dave
>
[quoted text clipped - 89 lines]
> >
> > Dave Peterson

Signature

Dave Peterson

Mike Rogers - 16 Dec 2005 04:24 GMT
Dave,

Thanks for all the help!!!! Everything works perfect.  I had a couple
different Worksheet_SelectionChange codes in some of the worksheets and
figured out how to combine them to work!!!!!  Did not know that could be
done!!!  Thanks for the help and the education.

Mike Rogers

> You'll have to combine them:
>
[quoted text clipped - 118 lines]
> > >
> > > Dave Peterson
Dave Peterson - 16 Dec 2005 17:07 GMT
It's nice when a plan comes together!

Glad you got it working.

> Dave,
>
[quoted text clipped - 131 lines]
> >
> > Dave Peterson

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.