Perform IF, ELSE, AND in a Loop

mojeeq

New Member
Joined
May 18, 2014
Messages
1
Hello, i'am trying to use macro to search through a column to find specific words
if it finds it, a value is assigned to the column next to it, it must be done in a loop and should read from each cell word by word, for example:

IF John Then ID = 256
IF John AND Smith Then ID = 231

Name ID
John Smith 231
Kurt Davis 127

This is probably simple for you guys but iam quite new at this :biggrin:
Thank You!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
My example have, lookupvalue in column A on sheet1, lookup range column A:B on sheet2 (Names, ID's)
Try:
Code:
Sub getId()


Dim x As Integer


lr = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row


For x = 2 To lr


On Error Resume Next
    With ThisWorkbook.Sheets("Sheet1")
        .Cells(x, 2).Value = WorksheetFunction.VLookup(.Cells(x, 1), Sheets("Sheet2").Range("A:B"), 2, 0)
    End With
Next x




End Sub
 
Upvote 0
mojeeq,

Welcome to the MrExcel forum.

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?

Can you post a screenshot of the actual raw data worksheet?

And, can you post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post your data, you can download and install one of the following two programs:
Download
MrExcel HTMLMaker20101230
https://onedrive.live.com/?cid=8cffdec0ce27e813&sc=documents&id=8CFFDEC0CE27E813!189

Or, when using Internet Explorer, just put borders around your data in Excel and copy those cells into your post.
See reply #2 the BLUE text in the following link:
http://www.mrexcel.com/forum/about-board/444901-how-create-table-like-aladin.html#post2198045


If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
Couldn't you assign the values to the column and use a VLOOKUP ???
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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