How to find cell value based on row and column ID in Excel VBA?

How to find cell value based on row and column ID in Excel VBA?

I want to find a specific value in a column based on two criteria. I want to search for the value "YES" in column D if A1 = 1 or B1 = 2 and then find the value "NO" in column D if A1 ! This is a simplified version of what I have in place now. I'm trying to figure out how to incorporate more variables.

This works to search for YES in all cells if "1" or "2" exist. Sub YES(). '
' YES Macro.
Dim LastCol As Long. Dim ws As Worksheet. Set ws = Sheets("Sheet1"). LastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column

For Each cell In ws.Range(ws.Cells(1, 1), ws.Cells(ws.Rows.Count, LastCol))
If cell.Value = 1 Or cell.Value = 2 Then
cell.Value = "YES" ElseIf cell.Value = 0 Or cell.Value = 1 Then
cell.Value = "NO" End If. Next cell. End Sub. The second part of the question asks me to use VBA to identify if "1" or "2" exist. For example: If A1=1 OR B1=2 and if A1=1 AND B1=0 then I want it to return "YES". I will need to do the same with "2" and "0".

One way: Sub YES(). Set ws = Sheets("Sheet1"). LastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Range(ws.Cells(1, 1), ws.Cells(ws.Count, LastCol))
If cell.Value = 2 Then If IsMissing(cell.

How to get cell value using cells in VBA?

I have an excel sheet that has many rows. I want to loop through all the rows and store the value of cell C3 in my code. Is it possible?
Here is the sample code. Sub Main(). Dim row As Long. For row = 2 To 100. If row = 3 Then. MsgBox "Value is:" & Cells(row, 3).Value End If. Next. End Sub. When I run this code, the code is skipping the third row and displaying the message box with the value from first row. The issue here is you are always resetting row back to 2 after you get to the 3rd row. Try this: Sub Main(). Do Until Cells(row, 3).Value Another option is to use a while loop: Sub Main(). While Cells(row, 3).

Related Answers

Does Excel 2016 have Macros?

After I used the Microsoft Office Assistant tool to clean up my Excel spreads...

Why won't macros work in Excel on Mac?

Macro (aka VBA) can be used to execute code automatically in Excel. This...

How do I use a cell value as a variable in VBA?

I have a cell in Excel which stores the value I want. Now I want...