Jul 24, 2008

Ms Excel : Search A Sheet

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > VB Programming

free web hosting

Ms Excel : Search A Sheet

kvarnerexpress
Anybody out there good with VBA and Excel? I am trying to search a sheet in a workbook (Sheet1), find out how many times particular values exists (int 1 to 54), then create a new workbook with a list of the values checked for and how many times they appeared.
Been googling this, but everything I have found just confused me more, never done much with Office before. Thanks in advance for any help!!

By the way, I am using Excel 2003 if that matters...

Reply

lava.alt
here is a little example of how to use excel for what you need ... this subrutine find how many times a value, that is between a range, appears ... i hope you find it useful ...

CODE
Private Sub LoadExcelFile()

   Dim FileDir   As String
   Dim Row, Col      As Integer
   
   Dim xlsApp    As Excel.Application
   Dim Book      As Excel.Workbook
   Dim Sheet1    As Excel.Worksheet
   Dim Sheet2    As Excel.Worksheet

On Error GoTo xError
   ' Assign object references to the variables. Use
   ' Add methods to create new workbook and worksheet
   ' objects.
   FileDir = App.Path & "\MyFile.xls"
   
   Set xlApp = New Excel.Application
   xlApp.Visible = True
   
   Set Book = xlApp.Workbooks.Open(FileName:=FileDir, ReadOnly:=False)
   Book.Activate
   
   Set Sheet1 = Book.Worksheets("Sheet1")
   Sheet1.Activate
   
   Set Sheet2 = Book.Worksheets("Sheet2")
   
   
   For Row = 1 To 10
       For Col = 1 To 5
           ' here we view is the value of the cell
           ' is between the range we need
           If (Val(Sheet1.Cells(Row, Col)) > 1) And _
              (Val(Sheet1.Cells(Row, Col)) < 10) Then
               
               Sheet2.Activate
               
               Sheet2.Cells(Sheet1.Cells(Row, Col), 1) = Sheet1.Cells(Row, Col)
               Sheet2.Cells(Sheet1.Cells(Row, Col), 2) = _
               Val(Sheet2.Cells(Sheet1.Cells(Row, Col), 2)) + 1
               
               Sheet1.Activate
               
           End If
       Next Col
   Next Row
   
   ' we save the changes
   Book.Save
   
   ' close the objects
   Book.Close
   xlApp.Quit
   
   ' clean them from memory
   Set xlApp = Nothing
   Set Book = Nothing
   Set Sheet = Nothing

Exit Sub
xError:
MsgBox "An error ocurred during the process"
End Sub


here is the matrix is use for the calc

the results appear in the second sheet

8 15 7 13 58
4 12 5 14 1
12 4 3 51 63
5 5 3 12 8
2 2 6 18 3
5 5 3 95 43
11 1 5 5 3
3 4 5 2 1
1 2 6 23 7
8 54 83 62 121

and the results i obtained are these

 

 

 


Reply

lava.alt
sorry i forgot to put the results

2 8
3 12
4 6
5 16
6 4
7 4
8 6

i recomend you to debug the program so you undestand what is doing ...

Reply

ARNEL
QUOTE(kvarnerexpress @ Jun 7 2005, 05:47 AM)
Anybody out there good with VBA and Excel? I am trying to search a sheet in a workbook (Sheet1), find out how many times particular values exists (int 1 to 54), then create a new workbook with a list of the values checked for and how many times they appeared.
Been googling this, but everything I have found just confused me more, never done much with Office before. Thanks in advance for any help!!

By the way, I am using Excel 2003 if that matters...
*



Lava.alt posted a nice script for your que, fore more info, try to look for windows help files from microsoft excel, there you will find a lot of tips with regards to your topics....

Reply

dul
At the moment macro language is better /MS offices/. You can use any MS Office macro command via OLE /Object Embedding Language/. It is quickest and easiest way.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. vba for searching sheet in excel - 0.24 hr back. (1)
  2. how to lookup from a particular tab in excel - 2.41 hr back. (1)
  3. search excel sheet for a value - 10.44 hr back. (1)
  4. how to search for the ~ in an excel sheet? - 10.89 hr back. (1)
  5. lookup multi sheet - 11.30 hr back. (1)
  6. search value in excel sheet - 19.27 hr back. (1)
  7. how many sheet can be found in a workbook in ms excel - 30.22 hr back. (1)
  8. howmany sheet can be found in a workbook in ms excel - 30.40 hr back. (2)
  9. search excel in sheet - 33.77 hr back. (1)
  10. excel - searching values - 35.22 hr back. (1)
  11. ms excel search - 42.11 hr back. (1)
  12. search cells in excel? - 48.82 hr back. (1)
  13. excel vb search sheet - 49.08 hr back. (1)
  14. how to search between excel sheets - 51.34 hr back. (1)
Similar Topics

Keywords : ms, excel, search, sheet

  1. Vlookup In Vba/excel
    Can't doooooo it :( (0)
  2. Excel Vb Form
    (2)
    I want to populate form values with data if the data chosen in a drop down menu matches with data
    that is already entered in to the excel sheet. The rest of the values are just textboxes. I was
    thinking if I could just force the value of the textbox to the data already entered in the sheet,
    but the form values are not changing. Please help! Code: Private Sub wellname_Change() num =
    Sheet2.Cells(1, 1) - 1 For Count = 1 To num Step 1 If wellname.Value = Sheet1.Cells(count, 1)
    Then UserForm1.point1.Value = Sheet1.Cells(Count, 2) UserForm1.point2.V....

    1. Looking for ms, excel, search, sheet

Searching Video's for ms, excel, search, sheet
advertisement



Ms Excel : Search A Sheet



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE