HI sorry I am new to VBA and this is only from me trying to self teach.
What I am trying to do is, for each column where there is an "X" replace that "X" with the column title.
Problem is I am struggling to:
a) get the code to do this for each column
b) this table is just an example the actual data is much longer so I don't want to specify how many rows.
Before code
Column1 z_SAP_A z_SAP_B Z_SAP_C
assistant X x
buyer X X
supply X x
manager x X
what I would like after code
Column1 z_SAP_A z_SAP_B Z_SAP_C
assistant z_SAP_A x
buyer z_SAP_B Z_SAP_C
supply z_SAP_A x
manager x Z_SAP_C
Currently what I have
Private Sub CommandButton1_Click()
Dim code As Variant, x As Variant, z As Integer
Dim i As Integer, a As Integer
code = "X"
z = 2
x = Cells(2, z).Value
a = 3
Do Until x = ""
For a = a To 7
For i = 1 To 7
If Cells(a, i).Value = code Then
Cells(a, i) = x
z = z + 1
End If
Next i
Next a
Loop
End Sub
I hope I have given you enough - apologies for my lack of knowledge on this!
thanks
What I am trying to do is, for each column where there is an "X" replace that "X" with the column title.
Problem is I am struggling to:
a) get the code to do this for each column
b) this table is just an example the actual data is much longer so I don't want to specify how many rows.
Before code
Column1 z_SAP_A z_SAP_B Z_SAP_C
assistant X x
buyer X X
supply X x
manager x X
what I would like after code
Column1 z_SAP_A z_SAP_B Z_SAP_C
assistant z_SAP_A x
buyer z_SAP_B Z_SAP_C
supply z_SAP_A x
manager x Z_SAP_C
Currently what I have
Private Sub CommandButton1_Click()
Dim code As Variant, x As Variant, z As Integer
Dim i As Integer, a As Integer
code = "X"
z = 2
x = Cells(2, z).Value
a = 3
Do Until x = ""
For a = a To 7
For i = 1 To 7
If Cells(a, i).Value = code Then
Cells(a, i) = x
z = z + 1
End If
Next i
Next a
Loop
End Sub
I hope I have given you enough - apologies for my lack of knowledge on this!
thanks