PC Review


Reply
Thread Tools Rate Thread

Delete Row Select Case

 
 
Little Penny
Guest
Posts: n/a
 
      19th Jan 2008
I am trying to get this code to delete every row if the value in
column B begins with "X1".

I'm getting a syntax error any help would greatly be appreciated

Error here - Select Case Left((c, 2), 2)



Complete code:



Sub DeleteRowCase()
Dim c As Long
Dim LastRow As Long

Application.ScreenUpdating = False
LastRow = Range("C65536").End(xlUp).Row
For c = LastRow To 2 Step -1

Select Case Left((c, 2), 2)

Case Is = "X1": .EntireRow.Delete

Next c

End Select

Application.ScreenUpdating = True


End Sub
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      19th Jan 2008
Select Case Left(cells(c, 2).value, 2)

or maybe better:

Select Case ucase(Left(cells(c, 2).value, 2))

And later...

Case Is = "X1": rows(c).Delete
or
Case Is = "X1": cells(c,2).EntireRow.Delete


Little Penny wrote:
>
> I am trying to get this code to delete every row if the value in
> column B begins with "X1".
>
> I'm getting a syntax error any help would greatly be appreciated
>
> Error here - Select Case Left((c, 2), 2)
>
> Complete code:
>
> Sub DeleteRowCase()
> Dim c As Long
> Dim LastRow As Long
>
> Application.ScreenUpdating = False
> LastRow = Range("C65536").End(xlUp).Row
> For c = LastRow To 2 Step -1
>
> Select Case Left((c, 2), 2)
>
> Case Is = "X1": .EntireRow.Delete
>
> Next c
>
> End Select
>
> Application.ScreenUpdating = True
>
>
> End Sub


--

Dave Peterson
 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      19th Jan 2008
Sub deleteif()
For i = Cells(Rows.count, "c").End(xlUp).Row To 2 Step -1
Select Case UCase(Left(Cells(i, "c"), 2))
Case Is = "X1": Rows(i).Delete
Case Else
End Select
Next i
End Sub



--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Little Penny" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am trying to get this code to delete every row if the value in
> column B begins with "X1".
>
> I'm getting a syntax error any help would greatly be appreciated
>
> Error here - Select Case Left((c, 2), 2)
>
>
>
> Complete code:
>
>
>
> Sub DeleteRowCase()
> Dim c As Long
> Dim LastRow As Long
>
> Application.ScreenUpdating = False
> LastRow = Range("C65536").End(xlUp).Row
> For c = LastRow To 2 Step -1
>
> Select Case Left((c, 2), 2)
>
> Case Is = "X1": .EntireRow.Delete
>
> Next c
>
> End Select
>
> Application.ScreenUpdating = True
>
>
> End Sub


 
Reply With Quote
 
Little Penny
Guest
Posts: n/a
 
      19th Jan 2008
Thank you Dave.





On Sat, 19 Jan 2008 14:29:29 -0600, Dave Peterson
<(E-Mail Removed)> wrote:

>Select Case Left(cells(c, 2).value, 2)
>
>or maybe better:
>
>Select Case ucase(Left(cells(c, 2).value, 2))
>
>And later...
>
>Case Is = "X1": rows(c).Delete
>or
>Case Is = "X1": cells(c,2).EntireRow.Delete
>
>
>Little Penny wrote:
>>
>> I am trying to get this code to delete every row if the value in
>> column B begins with "X1".
>>
>> I'm getting a syntax error any help would greatly be appreciated
>>
>> Error here - Select Case Left((c, 2), 2)
>>
>> Complete code:
>>
>> Sub DeleteRowCase()
>> Dim c As Long
>> Dim LastRow As Long
>>
>> Application.ScreenUpdating = False
>> LastRow = Range("C65536").End(xlUp).Row
>> For c = LastRow To 2 Step -1
>>
>> Select Case Left((c, 2), 2)
>>
>> Case Is = "X1": .EntireRow.Delete
>>
>> Next c
>>
>> End Select
>>
>> Application.ScreenUpdating = True
>>
>>
>> End Sub

 
Reply With Quote
 
Little Penny
Guest
Posts: n/a
 
      20th Jan 2008
Question.

I'm not a vba guru but why does the code work with declaring i as a
variable, and what is c?

Thanks




On Sat, 19 Jan 2008 14:51:42 -0600, "Don Guillett"
<(E-Mail Removed)> wrote:

>Sub deleteif()
> For i = Cells(Rows.count, "c").End(xlUp).Row To 2 Step -1
> Select Case UCase(Left(Cells(i, "c"), 2))
> Case Is = "X1": Rows(i).Delete
> Case Else
> End Select
> Next i
>End Sub
>
>
>
> --
>Don Guillett
>Microsoft MVP Excel
>SalesAid Software
>(E-Mail Removed)
>"Little Penny" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>>I am trying to get this code to delete every row if the value in
>> column B begins with "X1".
>>
>> I'm getting a syntax error any help would greatly be appreciated
>>
>> Error here - Select Case Left((c, 2), 2)
>>
>>
>>
>> Complete code:
>>
>>
>>
>> Sub DeleteRowCase()
>> Dim c As Long
>> Dim LastRow As Long
>>
>> Application.ScreenUpdating = False
>> LastRow = Range("C65536").End(xlUp).Row
>> For c = LastRow To 2 Step -1
>>
>> Select Case Left((c, 2), 2)
>>
>> Case Is = "X1": .EntireRow.Delete
>>
>> Next c
>>
>> End Select
>>
>> Application.ScreenUpdating = True
>>
>>
>> End Sub

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      20th Jan 2008

dim i as long
"c" meant column c

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Little Penny" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Question.
>
> I'm not a vba guru but why does the code work with declaring i as a
> variable, and what is c?
>
> Thanks
>
>
>
>
> On Sat, 19 Jan 2008 14:51:42 -0600, "Don Guillett"
> <(E-Mail Removed)> wrote:
>
>>Sub deleteif()
>> For i = Cells(Rows.count, "c").End(xlUp).Row To 2 Step -1
>> Select Case UCase(Left(Cells(i, "c"), 2))
>> Case Is = "X1": Rows(i).Delete
>> Case Else
>> End Select
>> Next i
>>End Sub
>>
>>
>>
>> --
>>Don Guillett
>>Microsoft MVP Excel
>>SalesAid Software
>>(E-Mail Removed)
>>"Little Penny" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>>I am trying to get this code to delete every row if the value in
>>> column B begins with "X1".
>>>
>>> I'm getting a syntax error any help would greatly be appreciated
>>>
>>> Error here - Select Case Left((c, 2), 2)
>>>
>>>
>>>
>>> Complete code:
>>>
>>>
>>>
>>> Sub DeleteRowCase()
>>> Dim c As Long
>>> Dim LastRow As Long
>>>
>>> Application.ScreenUpdating = False
>>> LastRow = Range("C65536").End(xlUp).Row
>>> For c = LastRow To 2 Step -1
>>>
>>> Select Case Left((c, 2), 2)
>>>
>>> Case Is = "X1": .EntireRow.Delete
>>>
>>> Next c
>>>
>>> End Select
>>>
>>> Application.ScreenUpdating = True
>>>
>>>
>>> End Sub


 
Reply With Quote
 
Little Penny
Guest
Posts: n/a
 
      20th Jan 2008


I just copied and pasted the code.I just don't understand why the
code worked without dim i as long.


Sub deleteif()
For i = Cells(Rows.count, "c").End(xlUp).Row To 2 Step -1
Select Case UCase(Left(Cells(i, "c"), 2))
Case Is = "X1": Rows(i).Delete
Case Else
End Select
Next i
End Sub





On Sun, 20 Jan 2008 12:11:03 -0600, "Don Guillett"
<(E-Mail Removed)> wrote:

>
>dim i as long
>"c" meant column c

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      20th Jan 2008
It's always good practice to declare your variables--but you don't absolutely
need to.

If you don't declare the variable, then excel/vba will make it a Variant
--just like if you explicitly did: Dim i as Variant

(I thought you wanted column B???)

Little Penny wrote:
>
> I just copied and pasted the code.I just don't understand why the
> code worked without dim i as long.
>
> Sub deleteif()
> For i = Cells(Rows.count, "c").End(xlUp).Row To 2 Step -1
> Select Case UCase(Left(Cells(i, "c"), 2))
> Case Is = "X1": Rows(i).Delete
> Case Else
> End Select
> Next i
> End Sub
>
> On Sun, 20 Jan 2008 12:11:03 -0600, "Don Guillett"
> <(E-Mail Removed)> wrote:
>
> >
> >dim i as long
> >"c" meant column c


--

Dave Peterson
 
Reply With Quote
 
Little Penny
Guest
Posts: n/a
 
      21st Jan 2008
Thanks


I do want column B. But now I understand the code and changes that I
need to make for any column.

Thanks Again


>It's always good practice to declare your variables--but you don't absolutely
>need to.
>
>If you don't declare the variable, then excel/vba will make it a Variant
>--just like if you explicitly did: Dim i as Variant
>
>(I thought you wanted column B???)
>
>Little Penny wrote:
>>
>> I just copied and pasted the code.I just don't understand why the
>> code worked without dim i as long.
>>
>> Sub deleteif()
>> For i = Cells(Rows.count, "c").End(xlUp).Row To 2 Step -1
>> Select Case UCase(Left(Cells(i, "c"), 2))
>> Case Is = "X1": Rows(i).Delete
>> Case Else
>> End Select
>> Next i
>> End Sub
>>
>> On Sun, 20 Jan 2008 12:11:03 -0600, "Don Guillett"
>> <(E-Mail Removed)> wrote:
>>
>> >
>> >dim i as long
>> >"c" meant column c

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Case problem when hitting the Delete key gab1972 Microsoft Excel Programming 2 14th Oct 2009 07:51 PM
translate VB select case to switch case problem Rich P Microsoft C# .NET 13 8th Aug 2009 06:07 PM
Case without Select Case error problem Ayo Microsoft Excel Misc 2 16th May 2008 03:48 PM
how to case select with case-insensitive string ? Tee Microsoft ASP .NET 3 23rd Jun 2004 08:40 PM
how to case select with case-insensitive string ? Tee Microsoft VB .NET 3 23rd Jun 2004 08:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:08 PM.