wsom-itg
asked on
Excel macro to select the first value in cell in a specific column
Hello,
I'm attempting to create a VBA macro in Excel that looks at a specific column (column D) which contains values of "male" and "female". It then needs to convert those to M and F. I've created the following macro that does this. However in it's current construction the user must select the values in the column. I would like to set the macro to run for a specific column D and change the values there. Please help.
Thanks
Sub ConvertGender()
Dim c As Range
For Each c In Selection.Cells
c.Value = UCase(Left(c.Value, 1))
Next
End Sub
I'm attempting to create a VBA macro in Excel that looks at a specific column (column D) which contains values of "male" and "female". It then needs to convert those to M and F. I've created the following macro that does this. However in it's current construction the user must select the values in the column. I would like to set the macro to run for a specific column D and change the values there. Please help.
Thanks
Sub ConvertGender()
Dim c As Range
For Each c In Selection.Cells
c.Value = UCase(Left(c.Value, 1))
Next
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Phillip,
I guess I should of added that it needs to have functionality to make it memory conservative, so that doesn't check the entire million+ rows of excel but only the ones with values in them
I guess I should of added that it needs to have functionality to make it memory conservative, so that doesn't check the entire million+ rows of excel but only the ones with values in them
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To be memory conservative, instead of using Columns(4), use Columns(4).SpecialCells(xl CellTypeCo nstants)
ASKER
Thanks alot for the help. Both solutions work. I really like the Rob's find and replace
Open in new window
after Dim c As Range
That will select column D, which I think is all that you are missing.