Use select sheet instead of "In Selection"

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
The following VBA works great, however I would like to change it to the active sheet or at least change it so the column does not highlight. There is another VBA about 3 steps down, that ends up un-bolding elements in my Column D. The name of my active worksheet is "72 Hr". I believe I will need to put something like Dim ws and Setws=Sheets('72 Hr"), but I just don't know how to properly get it in the right format.

VBA Code:
Sub IsolateTime()
Dim cel As Range
Range("D1:D100").Select
Range(Selection, Selection.End(xlDown)).Select
For Each cel In Application.Selection.Cells
cel.Value = Right$(cel.Text, 4)
Next cel
Selection.NumberFormat = "@"
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Does this do what you want?
VBA Code:
Sub IsolateTime()
Dim cel As Range
With Sheets("72 Hr").Range("D1:D" & Cells(Rows.Count, "D").End(xlUp).Row)
    For Each cel In .Cells
        cel.Value = Format(Right$(cel.Text, 4), "@")
    Next cel
    .NumberFormat = "@"
End With
End Sub
 
Upvote 0
Solution
Does this do what you want?
VBA Code:
Sub IsolateTime()
Dim cel As Range
With Sheets("72 Hr").Range("D1:D" & Cells(Rows.Count, "D").End(xlUp).Row)
    For Each cel In .Cells
        cel.Value = Format(Right$(cel.Text, 4), "@")
    Next cel
    .NumberFormat = "@"
End With
End Sub
That was perfect! Thank you!
 
Upvote 0
Hello, you helped me out a lot yesterday. I thought I could use the same basic concept for my other VBA which is similar. It does work, but the "For Each r In Selection" makes nothing happen. Just like the previous one, I just want the VBA to look for the word CALL and and ROLL in front of it for "ROLL CALL". I'm sorry for asking, but you were quick and I know the VBA would work fine if I had it look properly in Column D. Thank you again so much!
Sub addTextAtBeginningCell()
VBA Code:
 Dim r As Range
    With Sheets("72 Hr").Range("D1:D" & Cells(Rows.Count, "D").End(xlUp).Row)
    For Each r In Selection
        If r.Value = "CALL" Then r.Value = "ROLL " & r.Value
    Next
    End With
End Sub
 
Upvote 0
Like this:
VBA Code:
Dim r As Range
    With Sheets("72 Hr").Range("D1:D" & Cells(Rows.Count, "D").End(xlUp).Row)
    For Each r In .Cells
        If r.Value = "CALL" Then r.Value = "ROLL " & r.Value
    Next
    End With
 
Upvote 0

Forum statistics

Threads
1,214,517
Messages
6,119,984
Members
448,935
Latest member
ijat

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