Link to home
Start Free TrialLog in
Avatar of Magpie Bavarde
Magpie BavardeFlag for France

asked on

Help on VBA request (next step)

Hello,

Following this topic : https://www.experts-exchange.com/questions/29166890/Help-on-VBA-request.html

My request was perfectly answered by both of the proposals

I've chosen to use the second one as it's easier for me to understand, only problem is that sometimes I will have to use the macro when there are already numbers in column H

My fault as I first said column H was empty when it actually wont always be empty

Could you please help me change the macro so that it will not touch column H if there are already numbers within ?

Thank you very much for your help & kind regards,

Mélanie
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

You may tweak that like this...
Sub Findandcut()
Dim r       As Long
Dim LastRow As Long

LastRow = Cells(Rows.Count, "F").End(xlUp).row

For r = 1 To LastRow
    'Check if "C" appears in the column F
    If Range("F" & row).Value = "C" Then
        'Copy the respective cell from G to H and then blank the source cell at G.
        If Range("H" & r).Value = "" Then
            Range("H" & r).Value = Range("G" & r).Value
            Range("G" & r).Value = ""
        End If
    End If
Next

End Sub

Open in new window

Avatar of Magpie Bavarde

ASKER

Hello Neeraj,

I remember your kind help from the last time, glad to see you again ;)

Thanks for your proposal, I can't run the macro : got a :

Run-time error '1004':
Method 'Range' of object'_Global' failed

The debug tool yellows the line : "If Range ("F" & row).Value = "C" Then
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India 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
Perfect !! Thank you very much Neeraj :)
You're welcome Mélanie! :)