Dear all
hope you are doing well
I need help on a delete if code.
There are two spreadsheets on the same workbook; sheet1 with a column of numbers 1 - 950 and sheet2 with a panel where the top row is a set of numbers to be compared to sheet1 column. the operation would be to delete column data in sheet2 if the cell on top of this column does not exist among numbers in sheet1 column.
sheet1
Deals to keep
1
2
4
5
6
Sheet 2
SR NO 1 2 3 4 5
-240 0.001545 0.000267 0.007754 -0.002630 -0.002630
-239 0.003810 -0.009662 -0.009662 0.042933 0.003798
-238 -0.001717 -0.002862 -0.002862 0.029076 0.007287
-237 -0.013669 0.012070 0.012070 -0.001426 -0.003474
for example here, i want excel to detect that because there is no 3 in sheet1 column to delete the content of the column headed 3 in sheet 2.
hope that is clear enough for your kind help.
I have the following but it is not running, it is deleting from column no. 3 instead and not the whole column;
Sub DeleteCells2()
Dim rng As Range
Dim i As Integer, counter As Integer
'Set the range to evaluate to rng.
Set rng1 = ActiveSheet.Range("B6:AST6")
Set rng2 = Sheets("deals filtered").Range("C2:C919")
'initialize i to 1
i = 1
'Loop for a count of 1 to the number of rows
'in the range that you want to evaluate.
For counter = 1 To 1189
'If cell i in the range contains an "x",
'delete the row.
'Else increment i
If rng1.Cells(i) = rng2.Cells(i) Then
rng1.Cells(i).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Else
i = i + 1
End If
Next
End Sub
does it run differently if it is MS2007,2010, or 2013
Best wishes
sheet 2.pngsheet 1.png
Bookmarks