Skip to main content

Posts

Showing posts with the label VBA

Convert multiple excel worksheets into multiple pdfs

Macro

AUTO FIT COLUMN WIDTH with VBA

Multilookup function with vba

Merge same cells with VBA

Sub MergeSelectedRange() 'Declare variables Dim rng As Range Dim cell As Range Dim lastCell As Range Dim currentValue As String Dim lastValue As String 'Prompt the user to select the range Set rng = Application.InputBox("Select the range to merge:", Type:=8) 'Initialize the lastValue variable lastValue = rng.Cells(1, 1).Value 'Loop through the selected range For Each cell In rng currentValue = cell.Value If currentValue = lastValue Then 'If the current cell has the same value as the last cell, add it to the range If lastCell Is Nothing Then Set lastCell = cell Else Set lastCell = Union(lastCell, cell) End If Else 'If the current cell has a different value than the last cell, merge the range If Not lastCell Is Nothing Then lastCell.Merge Set la...