Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Cannot find Cell

Sorry for this easy question, but the months of Access Programming has warped
my mind of the many things I remembered in Excel. If I want to find the word
"Date", what do I need to add to my VB. Thanks!

With ActiveSheet.Range("a1:a50")

Set C = .Find("Date", LookIn:=xlValues)

ActiveCell.EntireRow.FillUp.Select
Selection.Delete shift:=xlUp

Secondly, will the second part of my code delete all the rows above the
"Date" row?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cannot find Cell

One way:

Option Explicit
Sub testme01()

Dim RngToSearch As Range
Dim LookForWhat As String
Dim FoundCell As Range

LookForWhat = "Date"

With Worksheets("sheet1")
Set RngToSearch = .Range("a1:a50")
With RngToSearch
Set FoundCell = .Cells.Find(what:=LookForWhat, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
End With

If FoundCell Is Nothing Then
MsgBox "Not Found"
Else
If FoundCell.Row = 1 Then
MsgBox "Found in row 1--not deleted!"
Else
.Range("A1:A" & FoundCell.Row - 1).EntireRow.Delete
End If
End If
End With

End Sub

Kou Vang wrote:

Sorry for this easy question, but the months of Access Programming has warped
my mind of the many things I remembered in Excel. If I want to find the word
"Date", what do I need to add to my VB. Thanks!

With ActiveSheet.Range("a1:a50")

Set C = .Find("Date", LookIn:=xlValues)

ActiveCell.EntireRow.FillUp.Select
Selection.Delete shift:=xlUp

Secondly, will the second part of my code delete all the rows above the
"Date" row?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Cannot find Cell

You need to ensure that Date was found and then select that cell for your
code to work...

Set C = .Find("Date", LookIn:=xlValues)
if C is nothing then
msgbox "Not Found"
else
C.select
'the rest of your code
endif
--
HTH...

Jim Thomlinson


"Kou Vang" wrote:

Sorry for this easy question, but the months of Access Programming has warped
my mind of the many things I remembered in Excel. If I want to find the word
"Date", what do I need to add to my VB. Thanks!

With ActiveSheet.Range("a1:a50")

Set C = .Find("Date", LookIn:=xlValues)

ActiveCell.EntireRow.FillUp.Select
Selection.Delete shift:=xlUp

Secondly, will the second part of my code delete all the rows above the
"Date" row?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Cannot find Cell

OMG! Yes, how forgetful of me! Of course I was finding it in my code, but I
wasn't even selecting it, that is why it was being selected! Thanks Jim! (I
hate Mondays!)

"Jim Thomlinson" wrote:

You need to ensure that Date was found and then select that cell for your
code to work...

Set C = .Find("Date", LookIn:=xlValues)
if C is nothing then
msgbox "Not Found"
else
C.select
'the rest of your code
endif
--
HTH...

Jim Thomlinson


"Kou Vang" wrote:

Sorry for this easy question, but the months of Access Programming has warped
my mind of the many things I remembered in Excel. If I want to find the word
"Date", what do I need to add to my VB. Thanks!

With ActiveSheet.Range("a1:a50")

Set C = .Find("Date", LookIn:=xlValues)

ActiveCell.EntireRow.FillUp.Select
Selection.Delete shift:=xlUp

Secondly, will the second part of my code delete all the rows above the
"Date" row?

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
Find & Replace: find part cell, replace whole cell katy Excel Worksheet Functions 3 April 3rd 23 01:20 PM
FIND / SEARCH text compare cell to string in 3rd cell nastech Excel Discussion (Misc queries) 0 October 29th 07 02:51 AM
Find First Non blank cell than find column header and return that value Silver Rose Excel Worksheet Functions 10 April 30th 07 05:56 PM
UDF code to find specific text in cell comments, then average cell values bruch04 Excel Programming 3 December 5th 05 10:01 PM
use find twice to find cell on a specific row captbluefin[_6_] Excel Programming 2 November 1st 03 08:22 PM


All times are GMT +1. The time now is 03:05 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"