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

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
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?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,630
Members
449,041
Latest member
Postman24

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