473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Filtering Data from Excel Table and Show It in VB

39
Hi there,
I need help processing data from Excel in VB. I have a MSHFlexgrid to show data extracted from Excel. I'm able to show a range of cells from Excel table to my Flexgrid, but that's it. The problem is, I can't filter the data I wanted to show from Excel table. Is it possible to filter Excel data using SQL command? I've tried several ways including SQL command like "select Name from tbcustomers where Name....."
Please help me, anyone.

This is the code i've made so far:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdShow_Click()
  2.     Dim xlapp As Excel.Application
  3.     Dim xlbook As Excel.Workbook
  4.     Set xlapp = New Excel.Application
  5.     Set xlbook = xlapp.Workbooks.Add
  6.  
  7.     Clipboard.Clear
  8.     With MSHFlexGrid1
  9.         .Col = 0
  10.         .Row = 0
  11.         .ColSel = .Cols - 1
  12.         .RowSel = .Rows - 1
  13.         Clipboard.SetText .Clip
  14.     End With
  15.  
  16.     With xlapp.ActiveWorkbook.ActiveSheet
  17.         .Range("A1:R8000").Select
  18.         .Paste
  19.     End With
  20.     xlapp.Visible = True
  21.     End
  22. End Sub
Thank you very much!
Nairda
Jun 21 '07 #1
6 2233
Killer42
8,435 Expert 8TB
If you have a look in the index of articles etc. at the top of the forum, there's an entry there on Excel which I think covers this pretty well.
Jun 21 '07 #2
nairda
39
If you have a look in the index of articles etc. at the top of the forum, there's an entry there on Excel which I think covers this pretty well.

Hi, thank you Killer42,
But I'm so sorry, I can't find the article you've told me.
I only found how to show only visible cells from filtered Excel table. It's not covering my problem.
My problem is I want VB to filter my Excel data and show it to my MSHFlexgrid.
I have an Excel table (tbstudents) contains a view columns (StudentName, Address, Grade, etc). I want to show all data of a student named "Charlie".
So, how to make VB search and show Charlie's data?

In Access database, I use this code:
Expand|Select|Wrap|Line Numbers
  1. "Select * from tbstudents where StudentName  = '" & Text1.Text & "'", con, adOpenKeyset, adLockOptimistic"
But I can't used it on Excel.table
Please help.

Nairda
Jun 22 '07 #3
Killer42
8,435 Expert 8TB
Oh, so you want to take the data from the FlexGrid, filter it, and place the result in Excel - is that right? Now sure how you'd go about that directly. The brief article I pointed out shows how to select only the visible cells after filtering in Excel.

Perhaps you could do a three-stage process? That is, paste to Excel, then apply the filter, then use the "select visible cells" from the sample and copy it somewhere else. Obviously this is not the most elegant way to go about it, but it may work until you can find something better.

Or, can you do the filtering before you take the data from Excel to place it in the FlexGrid? If so, then that sample will almost certainly be helpful.
Jun 22 '07 #4
nairda
39
Oh, so you want to take the data from the FlexGrid, filter it, and place the result in Excel - is that right? Now sure how you'd go about that directly. The brief article I pointed out shows how to select only the visible cells after filtering in Excel.

Perhaps you could do a three-stage process? That is, paste to Excel, then apply the filter, then use the "select visible cells" from the sample and copy it somewhere else. Obviously this is not the most elegant way to go about it, but it may work until you can find something better.

Or, can you do the filtering before you take the data from Excel to place it in the FlexGrid? If so, then that sample will almost certainly be helpful.

Thank you very much,
Yes, I want to take data FROM Excel, and then put it on my FlexGrid.
So, I have to filter the data from Excel before place it in my Flexgrid, right?
Is there anyway that VB could automate the Excel filtering so I don't have to filter Excel manually before place the data in my Flexgrid?

Thank you so much again.

Nairda
Jun 22 '07 #5
Killer42
8,435 Expert 8TB
So, I have to filter the data from Excel before place it in my Flexgrid, right?
I think that's probably the more efficient way (after all, why move data you don't want?) but certainly not the only way.

Is there anyway that VB could automate the Excel filtering so I don't have to filter Excel manually before place the data in my Flexgrid?
I'm sure there is. I don't recall the syntax, but it's easy to get Excel to generate the code for you. Just start recording a macro in Excel, then set the filter you want, then stop recording. Hopefully (works for most functions, but not all functions) the macro will now contain the code to do what you want. It should then be relatively simple to transfer that to your program.
Jun 22 '07 #6
nairda
39
I think that's probably the more efficient way (after all, why move data you don't want?) but certainly not the only way.

I'm sure there is. I don't recall the syntax, but it's easy to get Excel to generate the code for you. Just start recording a macro in Excel, then set the filter you want, then stop recording. Hopefully (works for most functions, but not all functions) the macro will now contain the code to do what you want. It should then be relatively simple to transfer that to your program.

Ok then,
I'll give it a try.
Thank you very much for your help.

Regards,
nairda
Jun 22 '07 #7

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

Similar topics

8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
3
by: Alex Ayzin | last post by:
Hi, I have a problem that might be easy to solve(possibly, I've just overlooked an easy solution). Here we go: I have a dataset with 2 datatables in it. Now, I need to do the following: if...
2
by: Niyazi | last post by:
Hi, I have to retrieve a data from AS400 DB2 and after working with data I have to export into one of existing Excel file. I can connect into specific library in AS400 DB2 using AS400...
3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
11
by: Hi5 | last post by:
Hi, I am new to access I usedto work in Oracle and Mysql. I am after a way that enables me to populate a database I designed in access with lots of data which can be sorted in excel sheets, ...
1
by: Luis Esteban Valencia | last post by:
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
7
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.