Link to home
Start Free TrialLog in
Avatar of wsom-itg
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
Avatar of Phillip Burton
Phillip Burton

start with:

Columns(4).select

Open in new window


after Dim c As Range

That will select column D, which I think is all that you are missing.
SOLUTION
Avatar of Phillip Burton
Phillip Burton

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wsom-itg

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
ASKER CERTIFIED SOLUTION
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To be memory conservative, instead of using Columns(4), use Columns(4).SpecialCells(xlCellTypeConstants)
Thanks alot for the help.  Both solutions work.  I really like the Rob's find and replace