473,566 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with my search macro for excel

21 New Member
I recently received help writing a search macro for excel, but now I am trying to change it up to use it in another spreadsheet, and I am having some troubles. I need it to search two cells one has a month (cell B4) and the other has a year(cell B5). The macro that I have works great for searching just the month, but I don't know how to change it to incorporate another cell with the year in it. I really appreciate the help this forum provides.
Below is the macro I am currently using.

Expand|Select|Wrap|Line Numbers
  1. Sub TextBox11_Click()
  2.      Dim searchNum As String
  3.  
  4.     searchNum = InputBox("Enter Month Year")
  5.     If searchNum = "" Then Exit Sub
  6.     Sheets("Archive").Select
  7.     Range("B99").Value = searchNum
  8.     Range("B100").Activate
  9.     For i = 1 To 120
  10.             ActiveCell.Value = "=vlookup(B99,B4:DQ53," & i & ",FALSE)"
  11.         ActiveCell.Offset(rowOffset:=0, columnOffset:=1).Activate
  12.     Next i
  13.  
  14.     Range("A1").Select
  15.     Sheets("Searched Report").Select
  16.     Range("A1").Select
  17.  
  18. End Sub
Aug 26 '08 #1
2 1942
jotr
21 New Member
Sorry I made a mistake the month is in column B starting in row 4 and the year is in column C starting in row 4! I also would like for there to be two separate text boxes for the month and year, which I know how to do that but I don't know how to combine the two columns into the search results. The same row will always have the month and year I am searching for if that helps at all. I have changed my code to incorporate the two text boxes to enter my search in, so I am going to relist it.

Expand|Select|Wrap|Line Numbers
  1. Sub TextBoxSearch_Click()
  2.      Dim searchNum As String
  3.      Dim intRng As Integer
  4.  
  5.     searchNum = InputBox("Enter Month")
  6.     If searchNum = "" Then Exit Sub
  7.     intRng = InputBox("Enter Year")
  8.     Sheets("Archive").Select
  9.     ActiveSheet.Unprotect
  10.     Range("B99").Value = searchNum
  11.     Range("C99").Value = intRng
  12.     Range("B100").Activate
  13.     For i = 1 To 120
  14.             ActiveCell.Value = "=vlookup(B99,B4:DQ53," & i & ",FALSE)"
  15.         ActiveCell.Offset(rowOffset:=0, columnOffset:=1).Activate
  16.     Next i
  17.  
  18.     Range("A1").Select
  19.     ActiveSheet.Protect
  20.     Sheets("Searched Report").Select
  21.     Range("A1").Select
  22.  
  23. End Sub
Thanks again
Aug 28 '08 #2
NeoPa
32,564 Recognized Expert Moderator MVP
This question was asked incorrectly, so the OP reposted as Excel VBA: Search Problems.
Sep 6 '08 #3

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

Similar topics

4
7160
by: Marc | last post by:
Hi all, I am trying to write an application where I need the ability to open an Excel spreadsheet and do basic read/write, insert rows, and hide/unhide rows. Using win32com I have been able to get the basics down as well as some examples displaying how to simply read and write. But the next step appears exponential. I haven never done...
0
2078
by: Alex | last post by:
i have a module in Access which opens an existing Excel file and envokes a macro within the Excel file to draw graphs. now i am trying to convert the Excel macro to an Access one so that the converted Access macro can do the same thing as the Excel macro does when i open the Excel file. Can anybody give me a hint? Thanks in advance! Alex
1
4555
by: Giganews | last post by:
I have an Access 97 database in which I am running an Excel macro through automation. The macro in Excel is as follows: Worksheets("Sheet1").Protect Password:="****", DrawingObjects:=True, Contents:=True, Scenarios:=True When I call this macro from the database all works fine except when I recorded the macro I deselected the "Select...
4
10090
by: Rich Wallace | last post by:
Is there a way to open an Excel file and either respond to or supress the Macro warning window via VB.NET? Dim oExcel As Excel.Workbook Dim sFilePath As String = "C:\DailyReport.xls" oExcel = GetObject(sFilePath) --> Throws Macro warning window oExcel.Unprotect("password")
2
3521
by: cr113 | last post by:
I just upgraded from Office 2000 to Office 2003. My VB.NET Excel macro calls don't work any longer. Here is how I make my Excel macro call from VB.NET: Dim objExcel as Excel.Application objExcel = New Excel.Application objExcel.Workbooks.Open(FileName:="c:\test.xls", ReadOnly:=True) objExcel.Run("test.xls!test.test")
9
3929
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result - I have read every post out there and spent hours trying to figure out the problem with no success whatsoever - I have constrained the problem to...
1
1356
by: eskelies | last post by:
Below you will find the code that I have written. I am asking it to search for an Excel file. Once it finds the correct dated Excel file it opens it. From there it is in search of information. I can't determine if the macro is working without fixing the following date - 1 issue. Any assistance would be greatly appreciated. I am using Excel 2003. ...
3
9912
by: ManuelValdez | last post by:
Hello everybody! I need your valuable help to get an Excel macro to delete the single zeros only and no the zeros containing numbers like 360, 90, etc., because if I chose the search and replace in the Edit option, then all the zeros containing the numbers 360, 90, 502, etc. will be deleted. Some nice person helped me with the following code...
0
898
by: arunbalait | last post by:
Hi Sorry I dont know where to post this question. Apologize if this is a wrong section I need a macro for finding duplicate entries in Excel. There are lost of Duplicate entries in various field in the excel files. I need to find the Duplicate entries in excel. Plz somebody provide me a macro to find Duplicate entries. Thanx
0
7666
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...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
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...
0
7951
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...
1
5484
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...
0
5213
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...
0
3643
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...
1
2083
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.