LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default .SpecialCells(xlCellTypeBlanks).Delete without going to the sheet

The whole macro is below, which does what I want. It is in a standard module and will be run from any of about 8 to 10 different worksheets.

This snippet deleting blank cells in a range ends up leaving me with the "Project Priorities" sheet as the active sheet.

Sheets("Project Priorities").Activate
Range(Cells(2, blnkCol - 2), Cells(blnkRow, blnkCol)) _
.SpecialCells(xlCellTypeBlanks).Delete (xlShiftUp)

How would I return to the original sheet (or never leave it) that I run the code on? I know I should be able to do work on cells on other sheet with no need to select the sheet, but my head is not getting around how to do it if the activesheet can be a different each time the code is executed.

Thanks,
Howard


Sub Delete_Task_Proj_Proir()

Dim tskCel As Range
Dim tskCol As Long
Dim TheTaskRng As Range ' input box selections
Dim aTsk As Range, aTskDel As Range, blkCel As Range
Dim blnkRow As Long, blnkCol As Long


On Error GoTo NotValidInput

Set TheTaskRng = Application.InputBox( _
Prompt:="Select green font COMPLETED Task/s in Column E" & vbCr & _
"For removal from ""Project Priorities"" sheet", Type:=8)

If Not TheTaskRng.Column = 5 Then
MsgBox "Column E cell selection only"
Exit Sub
End If

Application.ScreenUpdating = False

For Each aTsk In TheTaskRng

Set aTskDel = Sheets("Project Priorities").Cells.Find(What:=aTsk, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)


blnkRow = aTskDel.Row
blnkCol = aTskDel.Column


If Not aTskDel Is Nothing Then
aTskDel.Offset(, -2).Resize(1, 3).ClearContents
aTsk.Offset(, 3) = aTsk.Offset(, 3) & "PP Del"
End If

Sheets("Project Priorities").Activate
Range(Cells(2, blnkCol - 2), Cells(blnkRow, blnkCol)) _
.SpecialCells(xlCellTypeBlanks).Delete (xlShiftUp)

Next 'aTsk

NotValidInput:
Application.ScreenUpdating = True
End Sub
 
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
XL2002: Selection.SpecialCells(xlCellTypeBlanks).Select Trevor Williams Excel Programming 4 September 1st 08 02:04 PM
Work around to SpecialCells(xlCellTypeBlanks)... DanF Excel Discussion (Misc queries) 7 June 29th 08 07:36 AM
.SpecialCells(xlCellTypeBlanks).EntireRow.Delete ward376 Excel Programming 4 April 29th 08 08:38 PM
Check SpecialCells(xlCellTypeBlanks) for 0 blanks Gerry Verschuuren Excel Programming 4 September 29th 07 11:14 PM
specialcells(xlcelltypeblanks) Neil[_11_] Excel Programming 5 October 9th 03 10:11 AM


All times are GMT +1. The time now is 12:31 PM.

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

About Us

"It's about Microsoft Excel"