Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable calculation question EG Excel Worksheet Functions 1 October 19th 09 12:00 AM
Variable name question JTWarthogs Excel Discussion (Misc queries) 3 May 7th 09 02:22 PM
variable question peyman Excel Discussion (Misc queries) 3 October 16th 07 12:33 AM
Simple Variable Question Michael Kintner Excel Programming 1 November 24th 03 06:06 PM
Question: Macro overloading, passing variable number of arguments Frederik Romanov Excel Programming 1 July 8th 03 02:51 PM


All times are GMT +1. The time now is 04:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"