Use cell value in column and cell value in row to locate cell

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
174
Hello
I have a worksheet with a row listing elements. Example (C, Ca, Co, Cu, Mn). Then a column listing sample labels. Example (A-1, A-2, B-1, B-2)

Looks like this
1575914276451.png

How to use vba to place a C value for sample A-1?
Sheet name is "Summary"
I would like something like
VBA Code:
Sheets("Summary").Rows(3).Find(elsym).Offset(1).Value = WorksheetFunction.Average(posavgs)
At this point in the macro the current element being processed is referred to as "elsym"
The code works to locate the column
Of course offset wont work
I need to use the sample name to determine the row and the element symbol to determine the column.
Thanks for any help

Tom
 

Attachments

  • 1575914054336.png
    1575914054336.png
    4 KB · Views: 6

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi, an idea

Book1
ABCDEFGHIJKLM
1CCaCoCrCuMnFor testing purpose
2A-1B-1CoRange
3A-233$D$4
4B-1
5B-289.3
6
7
ThomasOES
Cell Formulas
RangeFormula
J3J3=MATCH(J2,$A$2:$A$5,0)
K3K3=MATCH(K2,$B$1:$G$1,0)
L3L3=ADDRESS(J3+1,K3+1)
Cells with Data Validation
CellAllowCriteria
J2List=code
K2List=symbol


VBA Code:
Option Explicit
'Hernan Torres, Mikel ERP
'December 9, 2019

Sub locate()
Dim xVal, yVal  As Long
Dim x, y As String
Dim fila, columna As Range
Dim cell As Range
Dim valor As Variant

Set fila = Sheets("ThomasOES").Range("B1:G1")
Set columna = Sheets("ThomasOES").Range("A2:A5")
MsgBox Range(fila.Address).Row

x = InputBox("Enter a symbol", "Mikel ERP")
y = InputBox("Enter a code", "Mikel ERP")
valor = InputBox("Enter a value for this intersection", "Mikel ERP")
Set cell = Cells(Application.Match(y, columna, 0) + 1, Application.Match(x, fila, 0) + 1)
'Cells(Application.Match(y, columna, 0) + 1, Application.Match(x, fila, 0) + 1) = valor
Range(cell.Address) = valor
MsgBox "Address for your input is " & cell.Address, vbInformation, "Mikel ERP by htorres"

End Sub
 
Upvote 0
Thanks htorres
I wanted to use index match and found this to work
VBA Code:
elsym = "C"
Set sumsht = ThisWorkbook.Sheets("Summary")
sumsht.Select
Set elrng = sumsht.Range("B3", Range("B3").Offset(, 50))
Set samprng = sumsht.Range("A4").Resize(Range("sampiece").Value)
Set sumrng = sumsht.Range("B4").Resize(Range("sampiece").Value, 50)
With Application.WorksheetFunction
    .Index(sumrng, _
        .Match("A-1", samprng, 0), _
        .Match(elsym, elrng, 0)) _
        .Value = "0.001"
End With
Works perfect except the sheet must be selected to set elrng, samprng, and sumrng
I want to remain on the sheet that is generating the data and have the index match value filled in Sheets("Summary")
Any ideas?
Tom
 
Upvote 0
I got it.
VBA Code:
Set sumsht = ThisWorkbook.Sheets("Summary")
Set elrng = Range(sumsht.Range("B3"), _
                sumsht.Range("B3").Offset(, 50))
Set samprng = Range(sumsht.Range("A4"), _
                sumsht.Range("A3").Offset(Range("Sampiece").Value))
Set sumrng = Range(sumsht.Range("B4"), _
                sumsht.Range("B3").Offset(Range("Sampiece").Value, 50))
With Application.WorksheetFunction
    .Index(sumrng, _
        .Match(Range("Samsheet").Value, samprng, 0), _
        .Match(elsym, elrng, 0)) _
        .Value = WorksheetFunction.Average(posavgs)
End With
This fills the cells on different sheet with the element value for each sample
 
Upvote 0

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

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