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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
What is the cell value when you get the error?
At a guess it doesn't have a "." in it.
 
Upvote 0
What is the cell value when you get the error?
At a guess it doesn't have a "." in it.

Sample cell content:
[TABLE="width: 144"]
<tbody>[TR]
[TD]2019.04.25 14:07:27
[/TD]
[/TR]
</tbody>[/TABLE]

It works if I use it on a manual range selection.
 
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,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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