+ Reply to Thread
Results 1 to 4 of 4

VBA Issues - referencing a cell value in VBA for Userform data entry

  1. #1
    Registered User
    Join Date
    07-01-2015
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2010
    Posts
    12

    VBA Issues - referencing a cell value in VBA for Userform data entry

    Hi,

    this might be a simple thing or I have missed something completely
    This is the current code for a userform to add data, however I want the form to add data to a sheet dependant on the name, which is in a cell, or whether I should add the name to userform and whether it would add the data to appropriate named sheet.

    Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("John") - this would be either from the userform or a reference to a cell on a sheet

    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

    If Trim(Me.txtDate.Value) = "" Then
    Me.txtDate.SetFocus
    MsgBox "Please enter the date"
    Exit Sub
    End If
    With ws
    .Unprotect Password:=""
    .Cells(iRow, 1).Value = Me.txtDate.Value
    .Cells(iRow, 2).Value = Me.txtTime.Value
    .Cells(iRow, 3).Value = Me.txtReason.Value
    .Protect Password:=""
    End With
    Me.txtDate.Value = ""
    Me.txtTime.Value = ""
    Me.txtReason.Value = ""
    Me.txtDate.SetFocus

    End Sub

    I have attached a sample to see if it helps make it clearer as to what I am trying to explain.

    Thanks in advance
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA Issues - referencing a cell value in VBA for Userform data entry

    This:
    Please Login or Register  to view this content.
    would be something like:
    Please Login or Register  to view this content.
    where cell A1 on Worksheet whatever contains the value John.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-01-2015
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: VBA Issues - referencing a cell value in VBA for Userform data entry

    Thanks, solved it, something so simple.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA Issues - referencing a cell value in VBA for Userform data entry

    You're welcome. Thanks for the rep.

    Always simple when you know how . But not so when you don't . It can be very frustrating ... I know from experience. The good thing is, you'll know it next time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] referencing listbox entry in new userform
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-27-2017, 07:59 AM
  2. [SOLVED] Referencing ListBox value in UserForm issues
    By strud in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-09-2014, 06:46 AM
  3. Data Entry By UserForm : Plus the value already in cell
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-13-2014, 06:23 AM
  4. Replies: 0
    Last Post: 02-04-2014, 12:36 AM
  5. Userform data entry by clicking on a cell instead of typing
    By olivierpbeland in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-08-2013, 02:17 PM
  6. Replies: 22
    Last Post: 12-15-2010, 08:49 PM
  7. Cell referencing issues to other worksheets.
    By RockECU in forum Excel General
    Replies: 9
    Last Post: 02-03-2009, 09:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1