Return the result of a formula after finding word in a string

andymalan

Board Regular
Joined
Feb 22, 2017
Messages
128
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
Hello good people of Mr Excel. I need to find a specific word in a string, when found, copy the RESULT of a formula (in a different cell) and paste it to a cell in the same row as where the word was found.
The code I have managed to put together so far, finds the word “substituted” and inserts the values I want, but I need it to return the result of a formula. E.g. Max(“sheet1!D2:D99”)
1659346105750.png


code<>
Sub CheckIfRangeOfCellsContainsSpecificText_vba()

Sheets("Cabinets").Select
'excel, if range of cells contains specific text vba
Set Rng = Range("I2:I1500") ' User can edit this
specificText = "substituted" ' User can edit this


For Each cell In Rng.Cells

If UCase(cell.Value) Like "*" & UCase(specificText) & "*" Then

cell.Offset(0, -5) = "600"
cell.Offset(0, -4) = "16"
' Else
' cell.Offset(0, 2) = " "
End If
Next
Calculate

I will be ever so grateful for your help.
kind regards
Andy
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hello good people of Mr Excel. I need to find a specific word in a string, when found, copy the RESULT of a formula (in a different cell) and paste it to a cell in the same row as where the word was found.
The code I have managed to put together so far, finds the word “substituted” and inserts the values I want, but I need it to return the result of a formula. E.g. Max(“sheet1!D2:D99”)
View attachment 70553

code<>
Sub CheckIfRangeOfCellsContainsSpecificText_vba()

Sheets("Cabinets").Select
'excel, if range of cells contains specific text vba
Set Rng = Range("I2:I1500") ' User can edit this
specificText = "substituted" ' User can edit this


For Each cell In Rng.Cells

If UCase(cell.Value) Like "*" & UCase(specificText) & "*" Then

cell.Offset(0, -5) = "600"
cell.Offset(0, -4) = "16"
' Else
' cell.Offset(0, 2) = " "
End If
Next
Calculate

I will be ever so grateful for your help.
kind regards
Andy
I am so hoping that someone can help with this problem I originally posted 4 days ago :-))
 
Upvote 0
You will get a better response if you provide an XL2BB of you data. It often takes longer to set up some test data than it takes to address the issue.
I am not sure of what you are trying to achieve so lets start with the below and see where that takes us.

VBA Code:
Sub CheckIfRangeOfCellsContainsSpecificText_vba_mod()

    Dim wsMain As Worksheet, wsGetData As Worksheet
    Dim rngDesc As Range, rCell As Range
    Dim specificText As String
    Dim lrGetData As Long

    Set wsMain = Worksheets("Cabinets")
    Set wsGetData = Worksheets("Sheet1")    ' <--- Put in correct sheet name
    lrGetData = wsGetData.Range("D" & Rows.Count).End(xlUp).Row
    
    'excel, if range of cells contains specific text vba
    Set rngDesc = wsMain.Range("I2:I" & Range("I" & Rows.Count).End(xlUp).Row) ' User can edit this
    specificText = "substituted" ' User can edit this
    
    For Each rCell In rngDesc.Cells
        If UCase(rCell.Value) Like "*" & UCase(specificText) & "*" Then
        
            'cell.Offset(0, -5) = "600"
            rCell.Offset(0, -5).Value = WorksheetFunction.Max(wsGetData.Range("D2:D" & lrGetData))
            rCell.Offset(0, -4) = "16"
            ' Else
            ' cell.Offset(0, 2) = " "
        End If
    Next
    Calculate           ' shouldn't be required
End Sub

My sheet: Cabinets
20220806 VBA Substitute and Formula andymalan.xlsm
ABCDEFGHI
1CodeHingeQuantityCol4Col5Col6Col7Col8Description
2F9001750900560F900Floor unit w/2 doors, 900mm
3F8501750850560F850Height=900, Rebuilt front Floo unit
4F7501750750560F750Height=825, Rebuilt front Floo unit
5FSS130016560FSS0Floor substituted side
6F9501750950560F950Floor unit w/2 doors, 950mm
7WT7501750750300WT750Depth=635 Wall transition unit w/2 doors
8814817508148008148Direction=Left strip handle bsn 256
Cabinets


My Sheet1

20220806 VBA Substitute and Formula andymalan.xlsm
ABCDE
1Max of this
2100
3200
4300
550
6150
7250
sheet1
 
Upvote 0
Solution

Forum statistics

Threads
1,223,725
Messages
6,174,134
Members
452,546
Latest member
Rafafa

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