if and vb code

jaypatel

Active Member
Joined
Nov 25, 2002
Messages
389
Hi all,

What would the vb code be for the following:
Where in column A, cell = “caseid” then delete the row above. Ie if cell a20=”caseid”, delete row 19

and

Where in column F, cell = “Commission due” drop that particular cell down 1 cell. Ie if commission due in cell F16, move cell F16 to F17;

thanks

Jay
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
What have you tried? Do you want to test column F before column A? If A17 contains "caseid" and F16 contains "Commision due", deleting row 16 would lose what's in F16.
 
Upvote 0
oh, sorry,

these are mutually exclusive, ie they would be worked on different sheets, but need the code to help with the analysis

Jay
 
Upvote 0
Try:

Code:
Sub TestA()
    Dim r As Long
    With ActiveSheet.Range("A1").CurrentRegion
        r = .Rows.Count
        Do While r >= 2
            With .Cells(r, 1)
                If .Value = "caseid" Then
                    .Offset(-1).EntireRow.Delete
                    r = r - 1
                End If
                r = r - 1
            End With
        Loop
    End With
End Sub

Sub TestF()
    Dim r As Long
    With ActiveSheet.Range("A1").CurrentRegion
        r = .Rows.Count
        Do While r >= 2
            With .Cells(r, 6)
                If .Value = "Commission due" Then
                    .Offset(-1).Cut .Offset(0)
                    r = r - 1
                End If
                r = r - 1
            End With
        Loop
    End With
End Sub
 
Upvote 0
Hi Andrew

I have tried the code, but the expected result has not happened.... actually nothing has happened when i run either of them.

I have checked whether it is case sensitive as well.

Sorry

Jay
 
Upvote 0
Both procedures worked when I test them. The code does assume that your data starts in A1 and is contiguous. Maybe it will help if you post a sample of your data.
 
Upvote 0

Forum statistics

Threads
1,219,165
Messages
6,146,681
Members
450,706
Latest member
LGVBPP

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