Population and matrix / array

JorgenKjer

Board Regular
Joined
Aug 1, 2016
Messages
65
Office Version
  1. 2013
Platform
  1. Windows
Hi

Is there anybody that can help with a VBA code?

I have a matrix, which must be filled in with "X"

If for example A2 matches C1, there must be an "X" in C2

The value in cells B1, C1, D1 and E1 is always the same.

The values in column A are variable and the number of rows is dynamic

I hope this makes sense

Thank you in advance for your help

Yours sincerely

Jørgen Kjer

A
B
C
D
E
1
1
2
3
4
2
2
X​
3
2
X​
4
2
X​
5
2
X​
6
4
X​
7
3
X​
8
1
X​
9
4
X​
10
2
X​
11
1
X​
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Thanks Fluff for your quick reply
I have created the matrix with a formula,
but to prevent someone from accidentally deleting the formula,
I feel it is safe to use a VBA code if possible.
The matrix is part of a larger project that I am trying to do with VBA coding.
However, my VBA knowledge is somewhat limited.
Regards Jørgen
 
Upvote 0
Ok, how about
VBA Code:
Sub JorgenKjer()
   Dim Ary As Variant
   Dim r As Long, c As Long
   
   Ary = Range("A1:E" & Range("A" & Rows.Count).End(xlUp).Row).Value2
   For r = 2 To UBound(Ary)
      For c = 2 To UBound(Ary, 2)
         If Ary(1, c) = Ary(r, 1) Then
            Ary(r, c) = "X"
         Else
            Ary(r, c) = ""
         End If
      Next c
   Next r
   Range("A1").Resize(UBound(Ary), UBound(Ary, 2)).Value = Ary
End Sub
 
Upvote 0
Hi Fluff
It's brilliant.
It works exactly as it should
Thank you
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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