ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   MACRO, help for making (https://www.excelbanter.com/excel-programming/369596-macro-help-making.html)

Marija

MACRO, help for making
 
Hi!
I will tell you concrete problem, which I have.

There, in the first sheet, I have a matrix with some numbers. In the second
sheet I have two columns with some values. I need that for the number from
matrix (from sheet 1) find the same number in the first column (from sheet 2)
and take value from the second column, same row (from sheet 2, too).
I tried to solve this problem, but no so successful!
Thanks in advance!

Graham Whitehead

MACRO, help for making
 
You have not specified what you want to do with the number in the second
column of the second sheet once it/they are found.

Anway, here is a small example - assumptions: a 4 by 4 matrix starting in
cell A1 on sheet 1. A column of 20 number on sheet 2 in columns A and B:

option base 1
dim x as integer
dim y as integer
dim intCounter as integer
dim array(16) as long '(change the variable type depending on your need
dim array2() as long '(again depending on the type of data in column B sheet
2)

intCounter=1
'store all values in the matrix
for x=1 to 4
for y=1 to 4
array(intCounter)=cells(x,y).value
intCounter=intCounter+1
next y
next x

'evaluate second sheet for matches
sheets("Sheet2").select
intCounter=1
for x=1 to 20
for y=1 to 20
if array(x).value=cells(y,1).value then
redim preserve array2(intCounter)
array2(intCounter)=cells(y,2).value
end if
next y
next x

Let me know if it works. I have just written this without excel in front of
me.


"Marija" wrote in message
...
Hi!
I will tell you concrete problem, which I have.

There, in the first sheet, I have a matrix with some numbers. In the
second
sheet I have two columns with some values. I need that for the number from
matrix (from sheet 1) find the same number in the first column (from sheet
2)
and take value from the second column, same row (from sheet 2, too).
I tried to solve this problem, but no so successful!
Thanks in advance!




llama

MACRO, help for making
 
Marija,

VLOOKUP([reference cell from your matrix], [Cell range from sheet 2
that has your 2 columns af data], [Column number to return data from,
in your case I assume it will be 2], False)

Llama


Marija

MACRO, help for making
 
Thank You llama. I have solved my problem by using your suport.

€žllama€ś je napisao:

Marija,

VLOOKUP([reference cell from your matrix], [Cell range from sheet 2
that has your 2 columns af data], [Column number to return data from,
in your case I assume it will be 2], False)

Llama




All times are GMT +1. The time now is 10:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com