If I use the "application.match" function to search for a string on two sheets. Is there someway to reference the cell not the XLvalue?.
That is, retrieve and store the cell location for a find function so that I can use that cell reference latter, to copy a value adjacent to it? Range 1 has unique cell values running horizontally. Range 2 runs vertically and can have duplicate values.
'sheet 2 tracking sheet
Sheet2.Visible = True
Set rng2 = Sheet2.Range("A1:A209") 'row and column vertically
'sheet 3 is where rng1 is found
Sheet3.Visible = True 'summary sheet(3)
k = 51 'starting row for copying too, on summary sheet
Set rng1 = Sheet3.Range("A4:HQ4") 'row and column horizontally
'set up the search
For Each cell In rng2
res = "" 'res = some string on sheet(2) in column 1
res = Application.WorksheetFunction.Match(cell.Value, rng1, 0) ' match string on sheet 2 with something on sht 3
If Not IsError(res) Then ' they match
' do something like start copying cell information
z = "" 'basically z = res
z = cell.Value 'set object from Match function
MsgBox cell.Value & " equals " & rng1(res).Value, vbOKOnly 'check it's working
I've found the matching cells, now if I use .find in this instance its OK-
Set rng7 = Sheets(3).Range("A4:HQ4").Find(what:=z, LookIn:=xlValues) 'find the correct cell
'using find will only ever find the first cell where the information is found but this is ok as the row values are unique.
Set rng8 = rng7.Offset(k, 1)
as there are only unique values in on the sheet .finf works OK.
Now if there are a number of cells with the same value on the next sheet .find doesn't work - I'd like this time to use a cell reference so that that cell can be used and not the first cell
say we have a1=101 b1=$7, a2=101 b2=$8, a3=109 b3=$52, a4=101 b4=$10,
The first column is accounting codes the second(B) is the value.
Match finds A1=101 and matches it with 101 on the second sheet.
But if I want to use a4, if I use find it will only stop at the first cell A1 but it is A4 I want - hence the need for a cell reference not xlvalue.
Possible?
Or is there another way to locate cells on different sheets and then use that cell reference to latter copy a value from (an adjacent cell) on the first sheet to the free cell that matches adjacent to the value on the second?
VB is needed. The code would reduce an 11meg sheet to around 383kb.
The original uses vlookup and if statements in each cell to copy data from sheet 3 to sheet 2.
Sheet 3 has infromation pasted to it from another workbook, the accounting codes are constant.
The idea is to use the code by clicking a command button once the new data has been added. Sheet 2 is a summary sheet and basically summs different accounting codes.
Everything in a simple -I hope - description.
Thanks
Bill