Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Ms Excel : Search A Sheet
kvarnerexpress
post Jun 6 2005, 09:47 PM
Post #1


Super Member
*********

Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



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...
Go to the top of the page
 
+Quote Post
lava.alt
post Jun 7 2005, 01:08 AM
Post #2


Advanced Member
*******

Group: Members
Posts: 125
Joined: 11-May 05
Member No.: 6,903



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
Go to the top of the page
 
+Quote Post
lava.alt
post Jun 7 2005, 01:09 AM
Post #3


Advanced Member
*******

Group: Members
Posts: 125
Joined: 11-May 05
Member No.: 6,903



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 ...
Go to the top of the page
 
+Quote Post
ARNEL
post Jun 27 2005, 03:25 AM
Post #4


Advanced Member
*******

Group: Members
Posts: 109
Joined: 18-May 05
Member No.: 7,198



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....
Go to the top of the page
 
+Quote Post
dul
post Oct 20 2005, 02:45 AM
Post #5


Member [Level 1]
****

Group: Members
Posts: 73
Joined: 21-September 05
Member No.: 12,113



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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics


 



- Lo-Fi Version Time is now: 22nd November 2008 - 08:12 PM