Option Explicit
Sub GetRange()
' Get ranges from the user to turn to Bold text. _
More ranges and on different sheets can be _
selected at once.
Dim vInp, vRanges, vEach, vCls, vSht
Dim lR As Long, lS1 As Long, lS2 As Long
Dim shts As Worksheet
vInp = Application.InputBox(prompt:="Select range to change to Bold using mouse." _
& vbCrLf & vbCrLf & "To add more ranges, type a """ & Application.International(xlListSeparator) _
& """ then select the" & vbCrLf & "next range. You can also add ranges on " _
& vbCrLf & "other sheets.", _
Title:="Select range", _
Type:=0)
If StrComp(Left(vInp, 1), "=") Then Exit Sub 'cancelled or invalid
vInp = Replace(vInp, "=", "")
If Len(vInp) Then
vRanges = Split(vInp, ",")
For lR = 0 To UBound(vRanges, 1)
vEach = Split(vRanges(lR), "!")
If UBound(vEach, 1) = 1 Then 'other sheet(s) than activesheet
If vEach(0) Like "*:*" Then 'grouped sheets
vSht = Split(vEach(0), ":")
lS1 = GetShtNr(CStr(vSht(0)))
lS2 = GetShtNr(CStr(vSht(1)))
For lS1 = lS1 To lS2 Step IIf(lS2 > lS1, 1, -1)
Set shts = Worksheets(lS1)
SheetRangeToBold shts, vEach(1)
Next lS1
Else 'single sheet
Set shts = Sheets(vEach(0))
SheetRangeToBold shts, vEach(1)
End If
Else 'no sheet name, so active sheet
Set shts = ActiveSheet
SheetRangeToBold shts, vEach(UBound(vEach, 1))
End If
Next lR
End If
'following because sometimes activesheet not displayed correctly
Set shts = ActiveSheet
Sheets(Sheets.Count).Activate
shts.Activate
End Sub
Sub SheetRangeToBold(shts As Worksheet, vAddress As Variant)
' set the range on the sheet to bold
Dim rRB As Range
Dim vRC1, vRC2, vCells
vCells = Split(vAddress, ":")
With shts
If UBound(vCells, 1) > 0 Then
vRC1 = CellsFromRC(vCells(0))
vRC2 = CellsFromRC(vCells(1))
Set rRB = .Range(.Cells(vRC1(0), vRC1(1)), .Cells(vRC2(0), vRC2(1)))
Else
vRC1 = CellsFromRC(vCells(0))
Set rRB = .Cells(vRC1(0), vRC1(1))
End If
End With
Range2Bold rRB
End Sub
Sub Range2Bold(rRange As Range)
'Turn range to bold
With rRange
.Font.Bold = True
.Font.Color = RGB(200, 20, 20)
End With
End Sub
Function CellsFromRC(sRC) As Long()
'Return row and column number form RC notation
Dim vS As Variant
Dim lRC(1) As Long
vS = Split(sRC, "C")
lRC(0) = CLng(Replace(vS(0), "R", ""))
lRC(1) = CLng(vS(1))
CellsFromRC = lRC
End Function
Function GetShtNr(sName As String) As Long
'return the order number of the worksheet
Dim sht As Worksheet
Dim lC As Long
For lC = 1 To Worksheets.Count
If StrComp(sName, Worksheets(lC).Name) = 0 Then
GetShtNr = lC
Exit For
End If
Next lC
End Function