Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

Macro : Copy Multiple Columns into 1 Continuous Column in a New Sheet

Below is a VBA Macro to copy multiple columns of variable length into one continuous column in a new sheet. Hope it helps you reduce the time at your work place.

Sub OneColumnV2()
''''''''''''''''''''''''''''''''''''''''''
'Macro to copy columns of variable length'
'into 1 continous column in a new sheet '
''''''''''''''''''''''''''''''''''''''''''
Dim iLastcol As Long
Dim iLastRow As Long
Dim jLastrow As Long
Dim ColNdx As Long
Dim ws As Worksheet
Dim myRng As Range
Dim ExcludeBlanks As Boolean
Dim mycell As Range

ExcludeBlanks = (MsgBox("Exclude Blanks", vbYesNo) = vbYes)
Set ws = ActiveSheet
iLastcol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
On Error Resume Next

Application.DisplayAlerts = False
Worksheets("Alldata").Delete
Application.DisplayAlerts = True

Sheets.Add.Name = "Alldata"

For ColNdx = 1 To iLastcol

iLastRow = ws.Cells(ws.Rows.Count, ColNdx).End(xlUp).Row

Set myRng = ws.Range(ws.Cells(1, ColNdx), _
ws.Cells(iLastRow, ColNdx))

If ExcludeBlanks Then
For Each mycell In myRng
If mycell.Value <> "" Then
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next mycell
Else
myRng.Copy
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next

Sheets("Alldata").Rows("1:1").EntireRow.Delete

ws.Activate
End Sub
Below are the steps to be followed to run the macro on the required data.
  1. Copy below mentioned VB Macro code
  2. Open Excel and Press Alt + F11 to open VB Project
  3. On left panel, Right click on "This Workbook" under VBA Project
  4. Go to Insert > Modules
  5. Paste the below copied VB code on the right white panel.
  6. Press Cltr + S to save the workbook
  7. Click on the Macro Button to copy every sheet to new workbook
  8. Enjoy.,

Find Last Blank Value (Space) in Excel Cell

How to find Last Blank Value, which is nothing but Space in a Excel Cell? This might be useful to get the Last word separated in to another column. For Example - You want to get City Name into the another column from the Address mentioned in the First column.

Firstly, Lets start with find the last blank value. Formula would be :

FIND("☃",SUBSTITUTE(A1," ","☃",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))

You can divide it into 3 parts:

How to Activate On Screen Keyboard (OSK) ?

How to activate On Screen Keyboard (OSK) in Windows Laptop / Computer ? Firstly you might thing why i would require to activate On Screen Keyboard ? The Answer is simple, when you require to use the Key (Like Scroll Lock)which is not provided on your physical keyboard.

Below are the two alternative methods to activate On Screen Keyboard :


Macro : Copy Excel Sheets as Workbook

How to copy every sheet in a excel workbook into a new workbook? Visual Basic (VB) Macro code (download a excel workbook) loaded with Excel Macro to Copy Every sheets to (as) New Workbooks with the Sheet Name converted into Workbook with just a click of macro button. You can use below macro code directly into the workbook, which requires sheets to be converted in to different workbook. You can also download a Sample copy of the Copy Every Sheet to New Workbook - Macro Enabled Worksheet.

Copy Every Sheet to New Workbook - Excel Macro
  1. Copy below mentioned VB Macro code
  2. Open Excel and Press Alt + F11 to open VB Project
  3. On left panel, Right click on "This Workbook" under VBA Project
  4. Go to Insert > Modules
  5. Paste the below copied VB code on the right white panel.
  6. Press Cltr + S to save the workbook
  7. Click on the Macro Button to copy every sheet to new workbook
  8. Enjoy.,

Sub Copy_Every_Sheet_To_New_Workbook()
'Working in 97-2010
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String

With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With

'Copy every sheet from the workbook with this macro
Set Sourcewb = ActiveWorkbook

'Create new folder to save the new files in
DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")
FolderName = Sourcewb.Path & "\" & Sourcewb.Name & " " & DateString
MkDir FolderName

'Copy every visible sheet to a new workbook
For Each sh In Sourcewb.Worksheets

'If the sheet is visible then copy it to a new workbook
If sh.Visible = -1 Then
sh.Copy

'Set Destwb to the new workbook
Set Destwb = ActiveWorkbook

'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2010
If Sourcewb.Name = .Name Then
MsgBox "Your answer is NO in the security dialog"
GoTo GoToNextSheet
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With

'Change all cells in the worksheet to values if you want
If Destwb.Sheets(1).ProtectContents = False Then
With Destwb.Sheets(1).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False
End If


'Save the new workbook and close it
With Destwb
.SaveAs FolderName _
& "\" & Destwb.Sheets(1).Name & "-" & Sourcewb.Name, _
FileFormat:=FileFormatNum
.Close False
End With

End If
GoToNextSheet:
Next sh

MsgBox "Visit http://routineinfo.com/ for More....Job Done Sir - You can find the files in " & FolderName

With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub

Hope this would have helped you save the time on excel and avoiding the routine work of copying all the sheets to a new workbook manually.... Stay tuned for more excel tips & technique i normally use in my office...

Note : - I am not the author of the Macro..

Enable Excel drag & drop option (+ sign in cell corner)

Excel problem ? Not able to get drag & drop option (plus (+) sign in bottom right corner of the cell), which help user to drag & drop the values in the incremental sequences. Don't worry, you have or due to some macro , your excel option of fill handle & drag & drop has got disabled. You need to activate (enable) the fill handle & drag-drop option again.
How to Enable Microsoft Excel Drag & Drop Option ? 
  1. Click File Menu 
  2. Go to the option (Excel 2010) 
  3. Click on the Advance tab on the left side of the window 
  4. Tick the 3rd option of Fill handle & drag-drop to enable your dragging option 
  5. That's All






Hope, this helps you .. would be posting on some of the more important & simple tricks as a daily dose of information @ Office

How to Show - Hide Status Sheet Tag Bar in Excel 2010 / 2007 ?

If you have lost your Status bar in Excel 2010 / 2007, it might be due to some macro or a option available in the Excel 2010 / 2007. You can show or even hide the status bar in Excel 2010 /  2007 via a option in build in the Excel and also via VBA trick. In Excel 2010, there is the in build option available for the users to show / hide the status bar in accordance to there need. Steps to Show - Hide Status Bar in Excel 2010 are as below :