VBA if cell = "text" then pull value from cell H if not pull cell value from G

L

Legacy 362125

Guest
Hi All

I am new to this forum and I am looking for some help if possible.

I have a worksheet which have VBA in it one of which references cell A2 and if that contains specific if it is true then pulls the value from cell H if not it pulls the value from cell G, I am also looking to copy the formula from cell J2 down to the last active cell

Here is the code - can anyone help ?

Code:
Sub Forecast()
Dim LastRowColumnA As Long
LastRowColumnA = Cells(Rows.Count, 1).End(xlUp).Row
Range("J2:J" & LastRowColumnA).Formula = IF(ISNUMBER(SERCH("Completed",A2)),H2,I2
End Sub

Thanks
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi All

I am new to this forum and I am looking for some help if possible.

I have a worksheet which have VBA in it one of which references cell A2 and if that contains specific if it is true then pulls the value from cell H if not it pulls the value from cell G, I am also looking to copy the formula from cell J2 down to the last active cell

Here is the code - can anyone help ?

Code:
Sub Forecast()
Dim LastRowColumnA As Long
LastRowColumnA = Cells(Rows.Count, 1).End(xlUp).Row
Range("J2:J" & LastRowColumnA).Formula = IF(ISNUMBER(SERCH("Completed",A2)),H2,I2
End Sub

Thanks
Hi CraigieL, welcome to the boards.

If I am understanding what you are trying to do correctly, try out the following in a COPY of your workbook:

Rich (BB code):
Sub CheckForTextValue()
' Defines variables
Dim Cell As Range, cRange As Range
    ' Defines LastRow as last row of data based on column A
    LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
        ' Sets check range as A2 to the last row of A
        Set cRange = ActiveSheet.Range("A2:A" & LastRow)
            ' For each cell in the check range
            For Each Cell In cRange
                ' If the cell value contains "text" (cell can be case insensitive but must be in caps here) then...
                If UCase(Cell.Value) Like "*TEXT*" Then
                    ' Update column J of the cell row with the value from column H of the cell row
                    ActiveSheet.Range("J" & Cell.Row).Value = ActiveSheet.Range("H" & Cell.Row).Value
                ' Else if the cell value does not contain "text" then...
                Else
                    ' Update column J of the cell row with the value from column G of the cell row
                    ActiveSheet.Range("J" & Cell.Row).Value = ActiveSheet.Range("G" & Cell.Row).Value
                End If
            ' Check next cell in check range
            Next Cell
End Sub
 
Upvote 0
Re: VBA if cell = "text" then pull value from cell H if not pull cell value from G (SOLVED

Hi CraigieL, welcome to the boards.

If I am understanding what you are trying to do correctly, try out the following in a COPY of your workbook:

Rich (BB code):
Sub CheckForTextValue()
' Defines variables
Dim Cell As Range, cRange As Range
    ' Defines LastRow as last row of data based on column A
    LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
        ' Sets check range as A2 to the last row of A
        Set cRange = ActiveSheet.Range("A2:A" & LastRow)
            ' For each cell in the check range
            For Each Cell In cRange
                ' If the cell value contains "text" (cell can be case insensitive but must be in caps here) then...
                If UCase(Cell.Value) Like "*TEXT*" Then
                    ' Update column J of the cell row with the value from column H of the cell row
                    ActiveSheet.Range("J" & Cell.Row).Value = ActiveSheet.Range("H" & Cell.Row).Value
                ' Else if the cell value does not contain "text" then...
                Else
                    ' Update column J of the cell row with the value from column G of the cell row
                    ActiveSheet.Range("J" & Cell.Row).Value = ActiveSheet.Range("G" & Cell.Row).Value
                End If
            ' Check next cell in check range
            Next Cell
End Sub



Thanks works like a dream, thanks again for your help
 
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,101
Members
449,066
Latest member
Andyg666

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