Apply formatting to user selected range

robdav

New Member
Joined
Dec 1, 2017
Messages
15
Hi

I'm trying to apply the following formatting to a user selected (via Application.InputBox) range of cells.

It keeps bugging out on the "Cell.Value = Replace(Expression:=Cell.Value, Find:=".", Replace:="/")" line

I'd be grateful if someone could help please.

Thanks

Rob

Code:
Sub FormatCells()


Dim rng As Range
Dim DefaultRange As Range
Dim FormatRuleInput As String


'Determine a default range based on user's Selection
  If TypeName(Selection) = "Range" Then
    Set DefaultRange = Selection
  Else
    Set DefaultRange = ActiveCell
  End If


'Get A Cell Address From The User to Get Number Format From
  On Error Resume Next
    Set rng = Application.InputBox( _
      Title:="Highlight Cells Yellow", _
      Prompt:="Select a cell range to highlight yellow", _
      Default:=DefaultRange.Address, _
      Type:=8)
  On Error GoTo 0


'Test to ensure User Did not cancel
  If rng Is Nothing Then Exit Sub
  
'Highlight Cell Range
        For Each Cell In rng
        Cell.Offset(0, 1).Value = Right(Cell, 8)
        Cell = Mid(Cell, 1, Len(Cell) - 9)
        Cell.Value = Replace(Expression:=Cell.Value, Find:=".", Replace:="/")
        Next


End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
What is the cell value when you get the error?
At a guess it doesn't have a "." in it.
 
Upvote 0
Try
Code:
        For Each cell In rng
        cell.Offset(0, 1).Value = Right(cell, 8)
        cell.Value = Mid(cell.Value, 1, Len(cell.Value) - 9)
        cell.Value = Replace(cell.Value, ".", "/")
        Next
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top