Name changing - Multiple procedures on given strings

shankl

New Member
Joined
Feb 13, 2018
Messages
2
Basically I am working with two columns and I want my code to:

1) Check column1 so it knows which row to stop on first (the end), then
2) Change the name in column1 on the condition that there is nothing in the same row in column2 (because we are filling the column2 in with the changed name), then
3) Then change the next name in column1 differently on the condition that there is nothing in the same row in column2 (because we are filling the column2 in with the next changed name), then
4) Loop back to the first name change method.

Name#1
NameChanged#1
Name#2
NameChanged#2

<tbody>
</tbody>

----------------------------------------------------------------PART 1--------
Code:
x_endrow = Range("A" & Rows.Count).End(xlUp).Row
  
    For i = 2 To x_endrow
    
        If IsEmpty(Cells(i, 2)) Then
        
            ...do something here to change the name         
    
        End If
----------------------------------------------------------------PART 2--------
Code:
    For i = 2 To x_endrow
    
        If IsEmpty(Cells(i, 2)) Then
        
            ...do something different here to change the name           
           
        End If
---------------------------------------------------------------------------------

I can get my code to work but only the first part.

PROBLEM #1 :

As soon as I add the second piece it complains about multiple of the same "For" statements or variables or something... I can't seem to put these pieces together correctly, I've tried a bunch of things like "Exit For" etc... but I'm stuck.PROBLEM #2 :

Also I am not sure how to get it to loop back to the first part to do that one again either...Any help is appreciated!!!

Thanks for your help!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
It looks like I can separate these out into Functions and then call them in a Sub!?

Code:
'---------------------------------------------------------------

Function NameChange1(ABC As String) As String
    Dim x_endrow As Long

    For i = 2 To x_endrow
    
        If IsEmpty(Cells(i, 2)) Then

            XYZ...do something different here to change the name

        End If
End Function

'---------------------------------------------------------------

Function NameChange2(XYZ As String) As String
    Dim x_endrow As Long

    For i = 2 To x_endrow
    
        If IsEmpty(Cells(i, 2)) Then
        
            XYZ...do something different here to change the name           
           
        End If
End Function

'---------------------------------------------------------------

Sub NameChangeGame()

    NameChange1

    NameChange2

End Sub()

I'll keep reading... see what else I can come up with...
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,086
Members
449,206
Latest member
ralemanygarcia

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