473,614 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel VBA question (Userform search field)

7 New Member
I have a userform that is used as an interface for information stored on excel spreadsheets. The user enters bits of information into fields on the userform which are place on the corresponding worksheet. I would like to have a txtBox that is used as a search field. When the user enters a number in the field it will search through column A of worksheet 1 for the value that was entered into the field. Once it is found I would like it to return the value of the cell that is two rows to the right of the found cell. So if the user enters the value "23" in the search field. If "23" is found in cell A49 I would like it to return the value in cell C49. What code will help me do this? Thank in advance.
Jan 16 '08 #1
1 4076
kadghar
1,295 Recognized Expert Top Contributor
(...) So if the user enters the value "23" in the search field. If "23" is found in cell A49 I would like it to return the value in cell C49. What code will help me do this? Thank in advance.
i'll asume your A column has no empty spaces, so i can use the END method:

Expand|Select|Wrap|Line Numbers
  1. dim a
  2. dim i as long
  3. with worksheets("sheet1")
  4.     a = range(.cells(1,3), .cells(1,1).end(-4121))
  5. end with
  6. for i = 1 to ubound(a)
  7.     if a(i,1) = textbox1.text then exit for
  8. next
  9. if i > ubound(a) then
  10.     msgbox("number not found") : exit sub
  11. end if
  12. msgbox a(i,3)
you can use cells(i,1) in your FOR and return cells(i,3), but its quite faster to import the entire range into a variant and work with it. (in this case 'a' is a variant, since is the default type, but you can also define it: Dim a as variant)
HTH
Jan 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2322
by: Paul Wagstaff | last post by:
Happy new year...hope someone can help with this.. The nub of this problem is to populate 2 tables in a 1-M relationship from an imported Excel spreadsheet. The problem being that there is nothing within the data that can uniquely identify a record. My mdb has 3 tables: tblImport (ID, CustName, Owner1, Process1, Owner2, Process2) tblComplaints (PK_Complaint_ID, CustName)
1
5727
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access database - containing a list of addresses. Sequence of events is = (1) Excel template opens in its default XXX.xls filename. (2) Code runs to save the spreadsheet as XXX.xls. (3) User clicks a button to open an Access database containing an
2
12500
by: hapnendad | last post by:
I am using a selection_change event on a worksheet to launch a userform that will populate the cell when a selection is made from a drop down list box on the form. Selection_change shows form if cell to the left of the active cell meets a certain condition and the active cell is in column 8. Problem: when conditions warrant, selection_change shows userform. when executed Excel locks. VBA editor indicates code is running but form can not be...
2
2185
by: NasirMunir | last post by:
I have created a table in access (copied from excel). Then I created a form which contains a text field and a list box. The text field is actually a look-up field, where a user can enter a searchable text and the results are displayed in the list box(the search is done on the table which I copied from excel). Everything works fine as I want. The problem: I cannot copy the results from that list box to the excel sheet. It just copies the first...
7
28886
Merlin1857
by: Merlin1857 | last post by:
Its great producing data for users to look at in your web pages and generally that is sufficient for their needs but sometimes you may want to supply your user with the data in a form they can actually do something more with. This code shows you how to display data from your database and then how to give that data to the user in the form of a useable Excel spreadsheet which they can then take away and play with themselves. The way I have shown...
3
3931
by: brenty66 | last post by:
I have a userform used as an interface to store information on excel spreadsheets. I have put a decent amount of work into it to this point and all of a sudden I am getting a catastrophic error message. It pops up every now and then when I try loading the userform. When I select OK it will then show a runtime Error 361 "Can't load or unload object" At this point it will usually close out of excel and ask to send an error report. Sometimes I...
1
1433
by: Pippy Parker | last post by:
I've created a Userform within an Excel session which is populated by various pieces of info. What I'm looking to do is exported the Userform into a jpeg which I then can attach to a e - mail. I've tried going down the Alt - Print Screen route but I'm unable to get the SendKeys "%{PRTSC}" command to work. Any ideas Many thanks
3
1671
by: mforema | last post by:
Hello, I have a userform in Excel with a textbox and cmd button. I want to give the user the ability to search for a specific worksheet name within an Excel Workbook. My code for the cmd button is as follows: Private Sub cmdSearchName_Click() Dim ChemName As String 'assigns user's entry to the variable "ChemName" ChemName = txtName.Value
3
11436
pod
by: pod | last post by:
Hello What I want to do is: from this workbook (thisWB), I want to access a userform's properties that are in another Workbook (toolWB) I can do this for worksheets, but I want to do it as well for the userform I have searched the help files, forums and went through all of the properties of workbooks and worksheets to no avail. I have a way to go around my problem but not without rewriting a lot of code.
0
8176
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8571
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8265
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8423
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5537
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4048
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2560
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.