+ Reply to Thread
Results 1 to 7 of 7

Entering data by cell heading through Userform

  1. #1
    Registered User
    Join Date
    12-02-2014
    Location
    Washington DC
    MS-Off Ver
    Office 2013
    Posts
    24

    Entering data by cell heading through Userform

    Hello,

    I'm very new to VBA and would greatly appreciate any help on this code...

    I have set up a Userform to enter data not only by category, but by date--I have both row and column headings. My userform includes a textbox (TextBox5) that I have coded to show the current date. I would like for my form entries (e.g., Boards, Bags, Boxes, Dowels, etc.) to fall into the column with the matching date heading on my spreadsheet. My userform captures quantities purchased, always integers.

    Here is what I have:

    Dim iColumn As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")
    Dim logday as Date
    Set logday = TextBox5.Value

    iColumn = ws.Range("B1:H1").Find(What:=logday, SearchOrder:=xlColumns, SearchDirection:xlPrevious, LookIn=Values).Column

    ws.Cells(2, iColumn).Value=TextBox1.Value
    ws.Cells(3, iColumn).Value=TextBox2.Value

    ...And so on down the row for the other textbox entries.

    The debugger tells me "Object required" and highlights the text I have bolded. But I thought that defining as "Date" was an Object type.

    Thanks so much for any help!
    Attached Images Attached Images

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Entering data by cell heading through Userform

    Date isn't an Object. Remove the "Set" and that error should go away.

    p.s. I know this is your first post, but you need to put your code in [CODE] brackets (the # button in the editor). You'll get a notice from the moderators.

  3. #3
    Registered User
    Join Date
    12-02-2014
    Location
    Washington DC
    MS-Off Ver
    Office 2013
    Posts
    24

    Re: Entering data by cell heading through Userform

    Thanks! For both tips.

    I removed the "Set" and got a new error: "Object variable or With block variable not set." I got this before, which is why I incorrectly thought that I needed the "set" in there. It highlights the "iColumn=..." line of code this time though. Am I defining "What" incorrectly?

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Entering data by cell heading through Userform

    You've got a couple syntax error in that line, You're missing an equal sign in SearchDirection and a colon in LookIn. Does it work after that?

    Please Login or Register  to view this content.
    FYI, it won't red-text a line because you have a wrong data type, just if you have syntax errors.

  5. #5
    Registered User
    Join Date
    12-02-2014
    Location
    Washington DC
    MS-Off Ver
    Office 2013
    Posts
    24

    Re: Entering data by cell heading through Userform

    Sorry, those were just errors I created in the posting--in the actual code reads as it should, as in your example. Still the same error, "Object variable ro With block variable not set."

  6. #6
    Registered User
    Join Date
    12-02-2014
    Location
    Washington DC
    MS-Off Ver
    Office 2013
    Posts
    24

    Re: Entering data by cell heading through Userform

    It works now! Unfortunately, I don't understand why. I fiddled with the "What:=" inserting different options, all of which failed. And when I put logday back in, it worked. Thanks so much for your prompt replies!!

  7. #7
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Entering data by cell heading through Userform

    I was just doing the same thing. Not sure what exactly was wrong, but glad it's fixed.

+ 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. VBA Userform (for Entering Data)
    By Faraei in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-22-2014, 10:48 AM
  2. [SOLVED] HELP Re entering Data to a previos cell using Excel Userform
    By eddyrcabrera79 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2013, 11:01 PM
  3. [SOLVED] Refresh UserForm after entering data in another userform
    By s2jrchoi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-30-2013, 10:34 AM
  4. Need help entering in data from userform
    By adamjohnson182 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2013, 08:15 PM
  5. Entering data from a Userform into a row
    By dougwild in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-18-2012, 10:52 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