Wednesday, 13 January 2016

Excel VBA Macro to Transpose Rows


Let us consider that a single column a contains data like below

Column A

L.saravanan
Data engineer
karaikkudi
Drk.kKarthikeyan
Ceo
Karaikkudi

if we transpose every three rows into column we get a valid data like below

ColumnA      ColumnB          ColumnC

L.saravnan    Data Engineer   Karaikkudi
Dr.K.K          Ceo                   Karaikuddi


Do it automatically we need a macro to transpose rows:-

  1. Right click sheet one and click view code
  2. Copy the below code and paste it.
  3. Click return back to Microsoft excel from Vb Window
  4. Now click view from excel ribbon
  5. Click view macro
  6. Click run Transpose macro
  7. Enter A1 and click ok
  8. Now enter number of rows to be transposed
  9. Click ok and witness the magic of code

Transpose Row Macro:-

Sub TransposeRows()

Dim lRows As Long, lCol As Long

Dim rCol As Range

Dim lLoop As Long

Dim wsStart As Worksheet, wsTrans As Worksheet

   On Error Resume Next

    'Get single column range

    Set rCol = Application.InputBox(Prompt:="Select single column", _
                                    Title:="TRANSPOSE ROWS", Type:=8)

                             

    'Cancelled or non valid range

    If rCol Is Nothing Then Exit Sub

 

    lRows = Application.InputBox(Prompt:="Transpose every x rows", _
                                        Title:="TRANSPOSE ROWS", Type:=2)

                                 

    'Cancelled

    If lRows = 0 Then Exit Sub

                                 
    'Make sure the transpositions will fit

    If lRows > ActiveSheet.Columns.Count Then

        MsgBox "Your 'transpose every x rows' exceeds the columns available"

        Exit Sub

    End If

 

    'Limit range to used cells

    lCol = rCol.Column

    Set rCol = Range(rCol(1, 1), Cells(Rows.Count, lCol).End(xlUp))

 

    'Set Worksheet variables

    Set wsStart = ActiveSheet

    Set wsTrans = Sheets.Add()

    wsStart.Select

 
    'Loop with step of x and transpose

    For lLoop = rCol(1, 1).Row To Cells(Rows.Count, lCol).End(xlUp).Row Step lRows

            Cells(lLoop, lCol).Resize(lRows, 1).Copy

            wsTrans.Cells(Rows.Count, "A").End(xlUp)(2, 1).PasteSpecial Transpose:=True

            Application.CutCopyMode = False

    Next lLoop

 
    On Error GoTo 0

End Sub

I think this will be useful to you friends.








Monday, 11 January 2016

Excel VBA Macro to Hilight Cursor



When we are using excel for a presentation or teaching purpose it is essential that the cursor is to
be highlighted to grab attention.This macro will highlight what ever you select are move.And here is Excel VBA Macro do it.

Hlite Cursor Excel VBA Macro:-

Right Click Sheet-1 and Click View Code

Copy and paste the following

Option Explicit

Double Click "This Workbook" in VB window


Copy and paste the following

Option Explicit
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
Static OldCell As Range

If Not OldCell Is Nothing Then
    OldCell.Interior.ColorIndex = xlColorIndexNone
End If

Target.Interior.ColorIndex = 6

Set OldCell = Target
 
End Sub

 Now return back to excel the cursor will be highlighted were ever you move

                                                         Or


Simply download highlight cursor workbook

Enable the macro options and use it



                            Click Here to Download Hlite Cursor Excel Workbook







VBA Macro to Merge Excel Files


Hi friends when we have large number of excel files with same columns and it is hard to combine it manually to a single excel file .But with the aid of this Vb Macro it is just like a piece of cake.


Put all the excel file in a single folder

Download the Merge Macro File

Open the the file

Enable the macro if you have disabled the macro

Click options and enable it in the security warning showed above in excel.

Click Addin option shown it the excel ribbon

Click open files and select the folder.

Select all the files in the folder by Ctrl+A and click open

You can now see all the files in adjacent sheets.

And now click merge files your files will merge automatically into a single file and copy and save it in a new excel sheet

Note: All excel file should have common column names .