Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7900915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:05:06+00:00 2026-06-03T09:05:06+00:00

I do not know if it is possible to implement this problem in VBA

  • 0

I do not know if it is possible to implement this problem in VBA or it must be done with VB. Net using Visual Studio.

Problem:
Excel has its search function and it is a pain if there many value available or you must find a value that far away from column A.

enter image description here

I would like to have something like this

enter image description here

In which I can specify what columns I want to display by their header name. Rearrange the column in the way I would like to, and ability to copy and paste. Like datagrid in Visual basic?
Is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:05:07+00:00Added an answer on June 3, 2026 at 9:05 am

    I have given below both the methods – VBA and VB.net (take your pick) 🙂

    USING VB.NET

    Place a DataGridView on your VB.net Form and also place a Button. Place this code in the Button

    Public Class Form1
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim masterTable As New DataTable
    
            Dim cnnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=""Excel 12.0 Xml;HDR=NO"";Data Source=""{0}"";"
    
            Using da As New OleDb.OleDbDataAdapter("select * from [Sheet1$] Where F1 = 'Test1'", String.Format(cnnStr, "C:\Book1.xlsx"))
                da.Fill (masterTable)
            End Using
            DataGridView1.DataSource = masterTable
        End Sub
    End Class
    

    And you are done 🙂

    SNAPSHOT

    I am using limited Data.

    enter image description here

    You can also change your string "select * from [Sheet1$] Where F1 = 'Test1'" to "select F1 as Name,F2 as PN, F3 as [Inventory Loc] from [Sheet1$] Where F1 = 'Test1'" to display the headers as below

    enter image description here

    EDIT

    In case you are wondering how to do it in VBA

    USING VBA

    Place a Listbox and a Command Button on a Form and then use this code.

    Option Explicit
    
    Private Sub CommandButton1_Click()
        Dim ws As Worksheet, ws1 As Worksheet
        Dim rng As Range
        Dim lastRow As Long
        Dim Ar As Variant
    
        Set ws = Sheets("Sheet1")
    
        lastRow = ws.Cells.Find(What:="*", After:=ws.Range("A1"), _
                  Lookat:=xlPart, LookIn:=xlFormulas, _
                  SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
                  MatchCase:=False).Row
    
        Set rng = ws.Range("A1:C" & lastRow)
    
        Set ws1 = Sheets.Add
    
        With rng
            ws.AutoFilterMode = False
            .AutoFilter Field:=1, Criteria1:="Test1"
            .SpecialCells(xlCellTypeVisible).Copy ws1.Range("A1")
            ws.AutoFilterMode = False
    
            lastRow = ws1.Cells.Find(What:="*", After:=ws1.Range("A1"), _
                      Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, _
                      SearchDirection:=xlPrevious, MatchCase:=False).Row
    
            Ar = ws1.Range("A1:C" & lastRow)
    
            Application.DisplayAlerts = False
            ws1.Delete
            Application.DisplayAlerts = True
        End With
    
        With Me.ListBox1
            .Clear
            .ColumnHeads = False
            .ColumnCount = 3
            .List = Ar
            .ColumnWidths = "50;50;50"
            .TopIndex = 0
        End With
    End Sub
    

    SNAPSHOT

    enter image description here

    MORE FOLLOWUP

    Hi Siddharth, thank you very much for both code. For VB. Net it is wonderful. For the VBA in Exel, is there any way that I can copy (using Ctrl + C) to copy the data – single row will be fine, although copy multiple rows is more desirable. I am able to replace “Test1” with textbox i49.tinypic.com/2ceq3yf.jpg – user1370854 5 hours ago

    Yes it is possible to copy the single selected or multiple selected items from the listbox to cliboard. To make the listobx multiselect, in the design mode, set the property of the listbox to fmMultiSelectMulti1. Next Add a command button and paste this code.

    This code is again based on the data I use above so amend it as applicable. When you press the Copy button, the data is copied to the clipboard and then you can simply use CTL V to paste the data where ever you want; for example in Notepad.

    Private Sub CommandButton2_Click()
        Dim MyData As DataObject
        Dim i As Long
        Dim strCopiedText As String
    
        Set MyData = New DataObject
    
        With Me.ListBox1
            For i = 1 To .ListCount
                If .Selected(i - 1) Then
                    strCopiedText = strCopiedText & _
                                    .List(i - 1, 0) & vbTab & _
                                    .List(i - 1, 1) & vbTab & _
                                    .List(i - 1, 2) & vbCrLf
                End If
            Next i
    
            If Len(strCopiedText) > 0 Then
                MyData.Clear
                MyData.SetText strCopiedText
                MyData.PutInClipboard
                MsgBox "Data copied to clipboard"
            End If
        End With
    End Sub
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is possible but I'm not really sure where to start. Has
I do not know if this is possible, but here goes. And working with
I know the following is not possible because the Enumeration's type has to be
Okay, I know that 1) this is probably not possible with CSS alone and
I don't know if its possible or not, but here's what I need. I'm
I know that it's not possible to style any given PHP but I do
Does anyone know why is it not possible to get the virtualpath when you
I know it is not recommended, but is it possible? The only references I
Is it possible to use reflection to know what the code is doing, not
I know that most people say, OH! It's not possible, use php or whatever...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.