Truncate & Round Based on multiple conditions

schiszm

New Member
Joined
Feb 21, 2011
Messages
2
Hi,

In row 1, there are variable titles populated in each cell through Column GG. I am trying to isolate the partial text "mean". Once each cell title has been found, a new range directly under that title is to be activated with each cell value truncated, then rounded. How can I successfully loop through each column and complete this request? I have one of my samples of incorrect syntax in which I am trying to use. Any suggestions would be fabulous!!


Sub StrugglingHere()
Dim x As Long
Dim cell As Range
Dim found As Range
x = 5
Set found = Cells.Find(What:="mean", LookIn:=xlValues, lookat:=xlPartial, SearchOrder:=xlByRows, _
SearchDirection:=xlNext)
Do Until found <> ""
If found Like "*mean*" Then ActiveCell.Offset(-1, 0).Range("A1:A9").Select
'ActiveSheet.UsedRange.Rows.Select
For Each cell In Selection
cell.Value = Round(Left(cell.Value, x), 1)
Next
Loop
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to Mr. Excel!

Please use the 'code' markers around you code for easier reading.

Try this.

Code:
Sub FindingMean()
Dim aCell As Range
Dim aCol As Range
Dim X As Long
X = 5
For Each aCol In ActiveSheet.Range("A1:GG1")
    If InStr(LCase(aCol), "mean") Then
        For Each aCell In Range(Cells(2, aCol.Column), Cells(10, aCol.Column))
            aCell.Value = Round(Left(aCell.Value, X), 1)
        Next
    End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

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