+ Reply to Thread
Results 1 to 5 of 5

Fill in fields from a macro

  1. #1
    Registered User
    Join Date
    12-16-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    3

    Fill in fields from a macro

    Hi, I'm a total beginner but have been trying to complete a project for work. Below is a description, any help would be appreciated.

    I have a form that I want to automatically fill in from a macro searching through a range. In Range "Site" I have a drop down validation for picking the correct site. Once a value is in that field I'm looking for it to take that information and check it against another range called "SiteandRegion" then put that information into the form. Here is what I've come up with so far.

    Sub auto_address()

    Dim Town, County, Code As String

    Let Town = WorksheetFunction.VLookup(Range("Site").Value, Range("SiteandRegion").Value, 3, False)
    Let County = WorksheetFunction.VLookup(Range("Site").Value, Range("SiteandRegion").Value, 4, False)
    Let Code = WorksheetFunction.VLookup(Range("Site").Value, Range("SiteandRegion").Value, 5, False)

    End Sub

    I think from what I've learned so far, that should collect the information? What I don't know is how to put that information into the cells. I've named the cells Town_1, County_1 and Code_1. Can anyone point me in the right direct plz.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Fill in fields from a macro

    Hi max,

    I'll rush through this as I am just leaving work... but reply with further problems and I'll get back to you.

    first, get rid of "Let". Simply Town = ... etc
    then if you named the cells, then you can use them as a range: (put this AFTER you have done your Town = ... County = ... etc.

    Please Login or Register  to view this content.
    Since I don't know your workbook, I can't verify your statements assigning the values to the variables, but looks logical enough.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    12-16-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: Fill in fields from a macro

    Thx for the reply Arkadi, I put that information into my macro and it didn't seem to work. I went over it time and time again and still nothing, UNTIL, On the macro sheet itself I pressed the " Run/Sub Userform (F5) and then it entered the information. How do I get it to run automatically as soon as the site is picked from the drop down menu?

    This is my code at the moment :

    Sub auto_address()

    On Error Resume Next

    Dim Town, County, Code As String

    Town = WorksheetFunction.VLookup(Range("Site").Value, Range("SiteandRegion").Value, 3, False)
    County = WorksheetFunction.VLookup(Range("Site").Value, Range("SiteandRegion").Value, 4, False)
    Code = WorksheetFunction.VLookup(Range("Site").Value, Range("SiteandRegion").Value, 5, False)

    Range("Town_1").Value = Town
    Range("County_1").Value = County
    Range("Post_Code_1").Value = Code

    End Sub

  4. #4
    Registered User
    Join Date
    12-16-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: Fill in fields from a macro

    Thx for all your help .. I finally worked it out and it is working fine :-)

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Fill in fields from a macro

    Hi max,
    Sorry I didn't get back to you sooner, but I'm glad you worked it out... my suggestion would have been to put the code in a worksheet change event.

    Cheers,

    Arkadi

+ 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. Auto fill macro for fields below the active field
    By Macgyver7 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-11-2014, 06:26 PM
  2. auto fill fields
    By ZoWiiEee in forum Excel General
    Replies: 2
    Last Post: 04-17-2012, 06:06 AM
  3. Macro or script to auto fill fields
    By Benjamin2008 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-29-2010, 05:28 PM
  4. Auto Fill Fields
    By mbesspiata in forum Access Tables & Databases
    Replies: 0
    Last Post: 03-19-2010, 09:24 AM
  5. Auto fill fields
    By Eucarionte in forum Excel General
    Replies: 1
    Last Post: 07-24-2009, 05:32 PM

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