Posts

Showing posts from May, 2014

How to Copy Only the Visible Rows of a Filtered Data in Excel using VBA

Image
You might be working on a project where you need to filter sets of data and create a raw data of that filtered sets of data to a new sheet or range. By default, Excel copies hidden or filtered cells in addition to visible cells. If some cells, rows, or columns on your worksheet are not displayed, you have the option of copying all cells or only the visible cells.  The following snippet allows you to automate the process in microseconds. [ VBA ] Public Function GetFilteredData() Dim rawWs As Worksheet 'RAW DATA WORKSHEET Dim tarWs As Worksheet 'TARGET WORKSHEET 'Replace this with your actual Worksheets Set rawWs = Sheets("Raw Data") Set tarWs = Sheets("Filtered Data Visualizations") Application.ScreenUpdating = False 'Clear old contents of the Target Worksheet tarWs.Range("A2:N" & Rows.Count).ClearContents '****************************************...

How to Get the Addresses of Visible Rows from a Filtered Data in Excel using VBA

Image
The following function allows you to get the Address of each visible rows from a filtered sets of data in Excel using VBA. [ VBA ] Dim FilteredRows as Variant Public Function GetFilteredRows(Optional ByVal RowPrefixed As Boolean) Dim Rng As Range, rngF As Range, rngVal As Range 'Ranges Dim val As Variant 'Range Value Dim i As Integer 'Counter Dim lRow as long 'Last Row Application.ScreenUpdating = False Sheets("Raw Data").Select lRow = WorksheetFunction.CountA(Range("A:A")) 'Set the range of all visible cells of the filtered data Set rngF = Range("A2", Cells(ActiveSheet.UsedRange.Rows.Count, _ Range("A2").Column)).SpecialCells(xlCellTypeVisible) For Each Rng In Range("$A2:$A$" & lRow) If Not Intersect(Rng, rngF) Is Nothing Then If rngVal Is Nothing Then Set rngVal = Rng Else ...

How to Populate Data from Textbox to Datagridview in C#/CSharp

Image
The following example allows you to populate data from a TextBox to DataGridView Control in C#/CSharp. using System; using System.Collections.Generic; using System.Windows.Forms; namespace TextBoxToDataGridView { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { DataGridView dgv = this.dataGridView1; //SET DATAGRIDVIEW PROPERTIES dgv.AutoGenerateColumns = false; dgv.AllowUserToAddRows = false; dgv.RowHeadersVisible = false; dgv.MultiSelect = false; //SETS UP THE COLUMN HEADERS dgv.Columns.Add("FName", "First Name"); dgv.Columns.Add("LName", "Last Name"); dgv.Columns.Add("Age", "Age"); } private void btnAdd_Click(object sender, Event...

Populate Website Directory Listing into ListView Control using C#/CSharp

Directory listings are just HTML pages generated by a web server. Each web server generates these HTML pages in its own way because there is no standard way for a web server to list these directories.  The web server you'd like to list directories from must have directory browsing turned on to get this HTML representation of the files in its directories. So you can only get the directory listing if the HTTP server wants you to be able to. [C#] using System; using System.IO; using System.Net; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions; namespace DirectoryListing { public partial class frmMainDownloader : Form { public frmMainDownloader() { InitializeComponent(); } public static string GetDirectoryListingRegexForUrl(string url) { return "<a href=\".*\">(?<name>.*)</a>"; } private void btnFetchUrl_Click(object ...

Populate Data into DataGridView using DataTable in C#/CSharp

The following snippet allows to populate data into DataGridView Control using DataTable in CSharp. First, we establish a connection to our database. string sConnect = "Data Source=" + Properties.Settings.Default.Server + ";Initial Catalog=" + Properties.Settings.Default.Database + ";"; if (Properties.Settings.Default.UseIntegratedSecurity) sConnect += "Integrated Security=SSPI;"; else sConnect += "User Id=" + Properties.Settings.Default.Username + ";Password=" + Properties.Settings.Default.Password + ";"; this.sSQLConnectString = sConnect; This DataTable returns the Books Table. public DataTable GetBooks() { string sql = "select * from Book order by ISBN13, ISBN10"; SqlDataAdapter da = new SqlDataAdapter(sql, sqlConnection); try { DataTable dt = new DataTable(); da.Fill(dt); return dt; } catch (Exception ex) { throw ex; ...

How to Kill or Start a New Background Process in C#/Csharp

The following snippet allows you to check if a process is already running in the background. If the process is already running it will prompt the user to whether start a new process or continue with the existing one that is running.         private void checkForDataInProgress()         {             if (!this.bConnectedToDatabase)                 return;             Process proc = new Process();             string sNumThreads = Properties.Settings.Default.NumberOfLocalThreads.ToString();             string sProcArgs = "\"" + this.sSQLConnectString + "\" \"" + Properties.Settings.Default.XMLSaveDir + "\" \"" + Properties.Settings.Default.DLLDir + "\" " + sNumThreads;             proc.StartInfo = new ProcessStartInfo(Properties.Settings.Default.DataImporterAp...

Handle Keypress Event on a Search Box in jQuery

Image
I have this problem before when I tried to search a keyword from a database using jQuery-AJAX-PHP. Where in the query is fired up multiple times which slows down process. After searching reading various solution for this problem. I've came up with the jQuery function below. This handles the keypress event of the textbox with an id keyword . $('#keyword').live('keypress', KeywordSearch); Javascript Function: function KeywordSearch(event) { if (event.handled !== true) { if (event.keyCode == 13){ var type = $('#searchType').val(); var keyword = $('#keyword').val(); var result = $.ajax({ type: "GET", url: "search.php?keyword=" + keyword + "&type=" + type, async: false}).responseText; $('#results').html(result); $('#myTable').fadeIn('fast'); event.handled = true; event.preventDefault(); } } }