Multiple "AND" , "OR" conditions and reference adjacent cells in Excel 2016 - vba

I have an excel sheet which has two worksheets,
Worksheet 1 is the dashboard and Worksheet 2 is the Data Sheet.In worksheet 2 I have
A B C D E F G
Customer ID date R Transaction payment Recency Score Frequency Score Monetary Score
20000679742 28-03-2017 100 15 1280225 1 3 3
The formula I am using in the Worksheet 1 is :
=IF(OR(DATA!G2 =1,DATA!G2=2),AND(OR(DATA!H2=4,DATA!H2=3)),"DATA!B2")
it is returning TRUE instead of the Value in the B2 cell in DATA Sheet, B2 is the Customer ID
what am I doing wrong? Any Idea??

First, you'll need to remove the quotes from "DATA!B2". Then I believe you want to return B2 if G2 is equal to either 1 or 2 AND H2 is equal to either 3 or 4. Otherwise, leave the cell blank. If so, try...
=IF(AND(OR(DATA!G2 =1,DATA!G2=2),OR(DATA!H2=4,DATA!H2=3)),DATA!B2,"")

Related

Looking for vlookup or VBA any formula

I have 2 different worksheet as below
1st worksheet as --
Column A
Column B
Name 1
Done
Name 2
Pending
Name 3
Working
Name 4
Pending
Name 1
working
Name 5
Name 1
Name 6
Done
2nd sheet - output
Column A
Column B
Name 1
Name 1
Name 2
Name 3
Name 5
Name 5
Name 6
on 2nd sheet i am looking for output on column B from 1st worksheet.
if next to Column A if user has updated comment then ignore
if any user has left any one comment blank than in 2nd sheet same user name to display
Thanks
tried by joining column A&B in worksheet 3 and then using Vlookup on 2nd sheet from worksheet 3.
this one solved the problem but i have like 20 worksheet like worksheet 1 which make excel very slow.
how can i do it directly from worksheet 1 to worksheet 2
Any formula or VBA will do so that excel dont get slow

How to create a named range of cells based on value of another column in excel vba

I have the following sheet of data
Channel Quarter Week value
a 1 1 5811
a 1 2 199
a 1 1 8111
a 2 2 881
a 2 1 124
b 2 2 1991
I need to update the value column based on the combination of Channel and Quarter columns (I have created a helper column which would serve as a key)
Helper Channel Quarter Week value
a1 a 1 1 5811
a1 a 1 2 199
a1 a 1 1 8111
a2 a 2 2 881
a2 a 2 1 124
b2 b 2 2 1991
From my VBA form, I have a created a dictionary with the names in these helper columns like
cellDict = [a1:= 1000, 2:= 2000, b1:= 500 etc]
Now I want to update the value of 'value' column on the basis of this dictionary in such a way that the cells corresponding to a1 be updated with 1000/3 each (As the number of rows for a1 is 3) and similarly cells corresponding to a2 be updated with 1000/2 each.
The attempt was to create a named range for value column with separate helper names and then iterate over each named range and update the cell value by taking the total value and dividing it by count of that named range
So, my question is how do I create a named range with value column on the basis of helper column so that I have (Assuming value is column V)
Range("a1") = V1:V3
Range("a2") = V4:V5 etc..
I think you can do this without named ranges in a lot easier way.
First of all, I assume the rows are sorted by your helper column!
Just find the first a1 in the helper column eg. with find method and get its row number as rowStart.
Then use WorksheetFunction.CountIf Method to count the occurrence of a1 in the helper column as rowCount. So rowEnd = rowStart + rowCount - 1.
Now you can loop like …
Dim iRow As Long
For iRow = rowStart to rowEnd
'use your dictionary and rowCount to replace values here.
'Example for accessing the cell:
Worksheets("MySheet").Cells(iRow, "E").Value = ""
Next iRow

Comparing and updating a sheet in Excel using VBA

So I am a student currently doing a vacation job at a company and have been tasked with maintaining and updating a database. The database is created on an excel spreadsheet. Now the issue that I am having is that I am unable to run a comparison.
In one workbook I have 2 sheets. Sheet 1 has 6 columns and sheet 2 has only 4 columns. I want to compare column A in sheet 1 and sheet 2, and if they are the same sheet, let sheet 2 values become those in sheet 1. That I can do, however, if column A from sheet 1 does not equal column A from sheet 2 the entire row from sheet 2 must be copied into sheet 1.
If A1 = A2 Then
B1 = B2
C1 = C2
D1 = D2
Else
'add into first empty row in sheet 1.
Your help would greatly be appreciated. Thank you
Maybe this will help.
This code will compare the data form column a in sheet 2 to the data from column a in sheet 1 and if they are the same, the first 4 column values in that row will be copied.
sub test
application.screenupdating = false
For i = 1 to x 'number of rows you want to search in
For j = 2 to 4
If sheets("sheet1").range("A"&i).value = sheets("sheet2").range("A"&i).value
then sheets("sheet2").Cells(i,j).value = sheets("sheet1").Cells(i,j).value
next j
next i
end sub
Tested and worked

Using VBA in Excel to create a macro to fetch data between worksheets

I have two sets of data that need to be collated, the first has a list of questions (workbook 1), the second Workbook where those same questions are spread out over 5 sheets with ID numbers associated with them. I need a macro that will take a value from workbook 1, search for it in the entire workbook 2 and then locate its ID value and then copy this value into the first workbook.
I've tried numerous codes but I can't get anything near working, the closest I came was using a index, match function but that only does one column, whereas i need approximately 15 columns (I.e the whole worksheet)
Any help would be great!
I'm assuming your Excel workbooks are structured something like the following (based on your description).
Workbook 1
Sheet 1
A1 "What is the answer to life and all its questions?"
A2 "Who is the creator of Linux?"
A3 "What is your favorite text editor?"
Workbook 2
Sheet 1
A1 "What is the answer to life and all its questions?" B1 103401
A2 "Who is the creator of Linux" B2 104113
Sheet 2
A1 "What is your favorite text editor" B1 101031
We can take the index values from column B of workbook 2 (corresponding to our questions in column A of workbook 1) and copy these to column B of workbook 1. I'll provide a solution of how you could easily do this with cell formulas.
Workbook 1
Sheet 1
A1 "What is ..." B1 =Index([workbook2.xlsx]Sheet1!$B$1:$B$100$,
Match(A1, [workbook2.xlsx]Sheet1!$A$1:$A$100,0))
A2 "Who is ..." B2 =Index([workbook2.xlsx]Sheet1!$B$1:$B$100$,
Match(A2, [workbook2.xlsx]Sheet1!A$1:$A$100,0))
...
You could do the same thing in column C for Sheet 2 of workbook 2
Workbook 1
Sheet 1
A1 "What is ..." C1 =Index([workbook2.xlsx]Sheet2!$B$1:$B$100$,
Match(A1, [workbook2.xlsx]Sheet2!$A$1:$A$100,0))
A2 "Who is ..." C2 =Index([workbook2.xlsx]Sheet2!$B$1:$B$100$,
Match(A2, [workbook2.xlsx]Sheet2!A$1:$A$100,0))
...
Then one of the columns B-E would contain the ID number and the rest of the columns would contain N/A. Note that I only search the first 100 rows of the first 5 sheets of workbook 2.

Compare 2 columns in different workbooks and retrieve cell value from a third column

I have 2 workbooks in Excel 2010 book1.xls and book2.xls, Example book1:
A B C D E
880006729 5016211 John $0.000
From this workbook i only need Column B which is the Employee number and Column E which will be the place where i get the data from the other workbook
Example book2:
A B C
5016211 Canada Sales
In this book I have these main columns but I only need column A and C. Both workbooks have more than 1000 rows im just showing and example of the data.
My goal is to search the value from book1 Column B (Employee Number) in book2, after it finds that specific number get the value in column C and paste it in Column E book1, In few words, I want to know which Business Unit each employee belongs to.
NOTE: book1 table can contain more than 1 row with same employee number, of course if this happens just repeat the word "Sales" using as reference the tables above.
the final table would look like this...
A B C D E
880006729 5016211 John $0.000 Sales
IN COLUMN E of book1.xls enter this formula and drag it down:
=VLOOKUP(B1,[Book2.xls]Sheet1!A1:C1000,3)
Change the A1:C1000 to the range that has all the values in book2