Do if value in a row and a value in a column

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
1,807
Office Version
  1. 365
Platform
  1. Windows
I have a loop that runs down column A (Starting in row 3 to LstRow). If there is a Value in in column A I offset 5 columns and add a formula.

I want to make this a little more dynamic and have it also look at G1 to see if there is a value there as well before I add the formula.

Is this possible?
 

Some videos you may like

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

apo

Well-known Member
Joined
Nov 3, 2008
Messages
581
Hi..

This will do what you want..

Note.. In the code below... the value i was looking for in Column A is "2".
The Value i am also looking for in G1 is "1".
If true .. I am inserting this formula into the F column.


Code:
Private Sub CommandButton1_Click()
Dim LastRow As Long
Dim L As Long
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row


For L = 3 To LastRow
        If Sheets("Sheet1").Cells(L, 1).Value = 2 And Sheets("Sheet1").Cells(2, 7).Value = 1 Then
            Sheets("Sheet1").Cells(L, 6).Formula = "=(2+2)"
            L = L + 1
        End If
Next L
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,310
Members
414,052
Latest member
Dual Showman

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
Top