Select Case Issue - Change Gender after finding the gender column

mmetzinger

Board Regular
Joined
Dec 30, 2010
Messages
61
Ok, this should be super easy but for the life of me I can't figure it out. I need some code that will find the column with the header of "Gender" and change the values from "M" and "F" to "Male" and "Female" but I keep running into issues. Can someone give me some super easy code to do this?

I want to use a Select Case statement so I can set all other found values as blanks.

Thanks!
 
Hi,
Not sure if this wouldn't be faster, why don't you use Find/replace? Select only the Column of your choice replace all M with Male and F with Female should do the trick. No?
 
Upvote 0
No, the find & replace method won't work because I need to have all values that are not M or F removed from the list. A lot of the time data such as U or Unknown will get entered which doesn't fit in our CRM system.
 
Upvote 0
Figured it out! Apparently I just needed some sleep.

Dim GenderRange As String

Range("A1").Select
Cells.Find(What:="Gender", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate

Range(Selection, Selection.End(xlDown)).Select
GenderRange = Selection.Address

Dim oneCell1 As Range

For Each oneCell1 In Range(GenderRange)
Select Case oneCell1.Value
Case "M"
oneCell1.Value = "Male"
Case "F"
oneCell1.Value = "Female"
Case "Male"
oneCell1.Value = "Male"
Case "Female"
oneCell1.Value = "Female"
Case "Gender"
oneCell1.Value = "Gender"
Case Else
oneCell1.Value = ""
End Select
Next oneCell1
 
Upvote 0
Code:
Dim GenderRange As String

    Range("A1").Select
    Cells.Find(What:="Gender", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    
        Range(Selection, Selection.End(xlDown)).Select
       GenderRange = Selection.Address
      
Dim oneCell1 As Range

For Each oneCell1 In Range(GenderRange)
    Select Case oneCell1.Value
                Case "M"
                oneCell1.Value = "Male"
                Case "F"
                oneCell1.Value = "Female"
                Case "Male"
                oneCell1.Value = "Male"
                Case "Female"
                oneCell1.Value = "Female"
                Case "Gender"
                oneCell1.Value = "Gender"
            Case Else
                oneCell1.Value = ""
    End Select
Next oneCell1



Try:
Code:
Sub Test()
Dim LastRow As Long
Dim i As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To LastRow
    Select Case Cells(i, 1).Value
    Case "M"
        Cells(i, 1).Value = "Male"
    Case "F"
        Cells(i, 1).Value = "Female"
    Case "Male"
        Cells(i, 1).Value = "Male"
    Case "Female"
        Cells(i, 1).Value = "Female"
    Case Else
        Cells(i, 1).Value = ""
    End Select
Next i
End Sub
 
Upvote 0

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