Searching...
Monday, July 16, 2012
4:50 AM

How to merge excel worksheets into one master worksheet

Previously i was working for some of my projects and got a problem to solve. Here i have providing a Visual  Basic script which will help you to merge lots of excel sheets it to one sheet (MasterSheet).



The code below will sequentially merge all existing worksheets (except the first) into the first worksheet.

Sub MergeSheets()
Const rRANGE = "A1:Z100"
Dim iSheet, iTargetRow As Long, oCell As Object, bRowWasNotBlank As Boolean
Dim iTop, iLeft, iBottom, iRight As Long
Sheets(1).Select: Sheets.Add
Sheets(1).Select
Cells.Select
Selection.Clear
bRowWasNotBlank = True
For iSheet = 2 To ThisWorkbook.Sheets.Count: DoEvents
For Each oCell In Sheets(iSheet).Range (rRANGE).Cells: DoEvents
If oCell.Column = 1 Then
If bRowWasNotBlank Then iTargetRow = iTargetRow + 1
bRowWasNotBlank = False
End If
If oCell.MergeCells Then
bRowWasNotBlank = True
If oCell.MergeArea.Cells(1).Row = oCell.Row Then
If oCell.MergeArea.Cells (1).Column = oCell.Column Then
Sheets(1).Cells(iTargetRow, oCell.Column) = oCell
iTop = iTargetRow
iLeft = oCell.Column
iBottom = iTop + oCell.MergeArea.Rows.Count - 1
iRight = iLeft + oCell.MergeArea.Columns.Count - 1
Sheets(1).Range(Cells(iTop, iLeft), Cells(iBottom, iRight)).MergeCells = True
End If
End If
End If
If Len(oCell) Then bRowWasNotBlank = True
Sheets(1).Cells(iTargetRow, oCell.Column) = oCell
Next oCell
Next
Sheets(1).Activate
End Sub

Place the code in ThisWorkbook and use Tools    Macro    Macros    Run to execute it or use Tools    Macro  Macros  Options to assign a shortcut for frequent use.

0 comments:

Post a Comment

Thanks For Your Valuable Time.

Labels

Hack (103) Download (85) Software (75) X goodies (74) Nokia (53) Unlock codes (47) 3G (38) GSM (37) N-Series (34) Internet (28) BSNL (27) Free SMS (26) Mobile Customization (26) Airtel (25) GPRS (24) Android (20) Fun With Mobile (20) Aircel (19) SYMBIAN (19) Samsung (19) iPhone (19) Vodafone (18) Application (16) Free MMS (16) LG (15) New Technology (15) Free Call (14) Google (14) China Mobile (13) Mobile Themes (13) Reliance (13) Sony Ericsson (13) Tutorial (13) Motorola (12) SMS (12) Broad Band (11) GPS (10) CDMA (9) Memory (9) News (9) Sim Card (9) TATA (9) Free Balance (8) Games (8) JAVA (8) Security (8) Bluetooth (7) Spice (7) Android 4.0 (6) Antivirus (6) ISD (6) Review (6) 4G (5) Dolphin (5) Password (5) STD (5) Apple (4) HTC (4) IDEA (4) Open-Source (4) Operating System (4) Smart (4) WiFi (4) Battery (3) Botnet (3) Code (3) Datacard (3) Forensics (3) Free Software (3) Google+ (3) LandLine (3) MP3 (3) Mobile Shoping (3) Mobile TV (3) Uninor (3) Developers (2) Fackbook (2) Free Internet (2) Gingerbread (2) Linux (2) Malware (2) Micromax (2) Microsoft (2) Penetration Testing (2) Proxy Server (2) Smart Phone (2) Top Free Moives (2) Tracker (2) USB Modem (2) Uninior (2) Windows 7 (2) iPod (2) Movies 2011 (1) Spy (1) Tablet. (1) Tata Docomo (1) USSD (1) VPN (1) Visual Basic (1) Windows 8 (1) Youtube (1)
 
Back to top!