VBA Help for a learner!

Sazzle14

New Member
Joined
Apr 12, 2011
Messages
20
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
 
MrKowz I could KISS you - amezin!!!!

That so works!!!!

Can I just thank you for the support from all of you for a newbie!!!!
I know I should not be doing this at 10.30pm anyway but I thought I was going to be up all night with this!!!! it means this fits nicely with everything else i've done.

loverrrly x
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
MrKowz I could KISS you - amezin!!!!

That so works!!!!

Can I just thank you for the support from all of you for a newbie!!!!
I know I should not be doing this at 10.30pm anyway but I thought I was going to be up all night with this!!!! it means this fits nicely with everything else i've done.

loverrrly x

A simple thanks is all we ask. ;)

Cheers!
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,246
Members
453,152
Latest member
ChrisMd

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