Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro Question - Variable
For i = LastRow To 1 Step -1
If Not (Range("K" & i).Value Like "911195") Then Range("K" & i).EntireRow.Delete End If Next 'i This piece of code deletes a row if the value in column "K" is not like "911195". How can I change this to delete whatever the value of cell "A2" is? Could I set this up as a variable? Each time I run this the value will not always be "911195" that I want to delete. Currently I go edit the macro each time. T.I.A. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro Question - Variable
For i = LastRow To 1 Step -1
If Not (Range("K" & i).Value Like "Range("A2").Value) Then Range("K" & i).EntireRow.Delete End If Next 'i -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Dayton" wrote in message ... For i = LastRow To 1 Step -1 If Not (Range("K" & i).Value Like "911195") Then Range("K" & i).EntireRow.Delete End If Next 'i This piece of code deletes a row if the value in column "K" is not like "911195". How can I change this to delete whatever the value of cell "A2" is? Could I set this up as a variable? Each time I run this the value will not always be "911195" that I want to delete. Currently I go edit the macro each time. T.I.A. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro Question - Variable
Before your code, add valA2 = Range("A2").Value. Make sure you Dim valA2,
depending on what data type it will be. Then your second line becomes If Not (Range("K" & i).Value Like valA2) Then HTH Ed "Dayton" wrote in message ... For i = LastRow To 1 Step -1 If Not (Range("K" & i).Value Like "911195") Then Range("K" & i).EntireRow.Delete End If Next 'i This piece of code deletes a row if the value in column "K" is not like "911195". How can I change this to delete whatever the value of cell "A2" is? Could I set this up as a variable? Each time I run this the value will not always be "911195" that I want to delete. Currently I go edit the macro each time. T.I.A. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Variable calculation question | Excel Worksheet Functions | |||
Variable name question | Excel Discussion (Misc queries) | |||
variable question | Excel Discussion (Misc queries) | |||
Simple Variable Question | Excel Programming | |||
Question: Macro overloading, passing variable number of arguments | Excel Programming |