Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting range with variables

Status
Not open for further replies.

pglover

Technical User
Jul 18, 2001
33
GB
Hi folks

Assistance required please, and thanks to all for reading...

I have a spreadsheet containing a number of text entries in column C. I want to delete a number of rows starting at the row containing text 'start' and ending with the row containing the text 'finish' (for example).

I can create variables which find the appropriate text, and set amount - but cannot work out how to set the last bit - delete the range...


Set c = .Find("C:\DELL", LookIn:=xlValues)
firstRw = c.Row
Set d = .Find("C:\DELLUTIL", LookIn:=xlValues)
secondRw = d.Row

Rows("firstRw:secondRw").Select

Selection.Delete Shift:=xlUp


I would be grateful for any assistance...

Thanks

Penny
 
Hi
You have a couple of options for this

This what you were trying to do above but note the position of the quotes
Code:
Rows(firstRw & ":" & secondRw).Delete

This is just another option
Code:
Range(Cells(firstRw, 1), Cells(secondRw, 1)).EntireRow.Delete

Note also that in both cases there is no need to 'select' before deleting. If you need to know more check out SkipVought's FAQ on making code work faster.

Happy Friday
;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
Something like this ?
Rows(firstRw & ":" & secondRw).EntireRow.Delete Shift:=xlUp

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Excellent

Thank you both very much.

Penny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top