Excel - Merge Cells into One

This code will convert the cells you have selected into one cell.

Public Sub MergeCells()
sMergeStr = ""
Const sDELIM As String = ", "
Dim rCell As Range
With Selection
For Each rCell In .Cells
sMergeStr = sMergeStr & sDELIM & rCell.Text
Next rCell
Application.DisplayAlerts = False
'.Merge Across:=False
Application.DisplayAlerts = True
sMergeStr = Mid(sMergeStr, 1 + Len(sDELIM))
'.Item(1).Value = sMergeStr
End With
End Sub

The sDELIM can be changed to insert something else to break up the combined text, numbers, etc.

Excel - Remove Hyperlinks - Links

This is a major bit of coding by me, so many spreadsheets refer to external data, links, files and if you are editing it, just one click and it tries to open it. So annoying. This will copy everything but the links to another sheet in the same Workbook.

Tried and tested. I have search the internet and not found anything like this that works.

Sub RemoveLinks()
Dim WS As Worksheet
Cells.Select
Selection.Copy
'Set WS = Sheets.Add
Sheets.Add.Name = "WithoutLinks"
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _

Excel - Remove All Filters

Code to remove all filters. Can save time when you have a large spreadsheet and can't find which filter is on.

Sub removeallfilters()
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
End Sub

Excel - Activate Filters

The following code activates filters.

Sub viewrfa()
On Error Resume Next
Set w = ActiveSheet
w.Cells.AutoFilter field:=75, Criteria1:="YES", Operator:=xlOr, Criteria2:="Important"
End Sub

field = column number starting from the left ie E = 5
criterial = Filter By, only works if field contains one of those values, ie YES, NO, DATE, etc.

Excel - Easy Cell Colours

By using VBA you can define the colours of your choice and make it easier to change them for your users.

First Section is to create a menu.

Sub AddMenus()
Dim cMenu1 As CommandBarControl
Dim cbMainMenuBar As CommandBar
Dim iHelpMenu As Integer
Dim cbcCutomMenu As CommandBarControl
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("&Colour").Delete

Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
iHelpMenu = cbMainMenuBar.Controls("Help").Index

Set cbcCutomMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup, Before:=iHelpMenu)

Excel - Create Menu - Week No

Code to create a menu of your choice in Excel.

This example creates 2 menus.

By using the & symbol before the menu name you create Keyboard Shortcuts.

One of the menu's is a blank menu as it displays the current week no.

You can get the menu to automatically load by putting the code in the Workbook_Open() Sub.

Sub AddMenus()
Dim cMenu1 As CommandBarControl
Dim cbMainMenuBar As CommandBar
Dim iHelpMenu As Integer
Dim cbcCutomMenu As CommandBarControl
Dim wkno As String
Dim InputDate As Long
Dim A As Integer, B As Integer, C As Long, D As Integer

Syndicate content