Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default An Easy Mod For Sure

Hi, I'm having a bit of trouble with this code and would appreciate
some help.

It essentailly is working however when it copies the data to the
"Found" page it always leaves the first row "1" blank and I am fairly
sure it's because of this line:
lRow = wksFound.Cells(Rows.Count, 1).End(xlUp).Row + 1

What I want to do is place the result of my initial search in row 1
then any further search results in row 2, then row 3 etc etc

Hoping someone could offer some assistance.

Kind Regards,
Dean


Public Sub vbaCopyToAnotherSheet()
Dim rCell As Excel.Range
Dim rRow As Excel.Range
Dim wksFound As Excel.Worksheet
Dim wksData As Excel.Worksheet

Dim szLookupVal As String
Dim szRowAddy As String

Dim lRow As Long


Set wksFound = Sheets("Found") 'Sheet that gets the copied data
Set wksData = Sheets("Database") 'Sheet that contains the data to
search


lRow = wksFound.Cells(Rows.Count, 1).End(xlUp).Row + 1

szLookupVal = InputBox("What are you searching for", "Search-Box",
"")
If Len(szLookupVal) = 0 Then Exit Sub

With wksData.Cells

Set rCell = .Find(szLookupVal, , , , , , False)
If Not rCell Is Nothing Then

szRowAddy = rCell.Address

Set rRow = rCell

Do

Set rCell = .FindNext(rCell)

Set rRow = Application.Union(rRow, rCell)

rRow.EntireRow.Copy wksFound.Cells(lRow, 1)

Loop While Not rCell Is Nothing And rCell.Address < szRowAddy

End If
End With

Set rCell = Nothing
Set rRow = Nothing
Set wksFound = Nothing
Set wksData = Nothing
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default An Easy Mod For Sure

If wksFound.Cells(1, 1).Value < "" then
lRow = wksFound.Cells(Rows.Count, 1).End(xlUp).Row + 1
Else
lRow = 1
End if

HTH,
Bernie
MS Excel MVP


"Dean" wrote in message
oups.com...
Hi, I'm having a bit of trouble with this code and would appreciate
some help.

It essentailly is working however when it copies the data to the
"Found" page it always leaves the first row "1" blank and I am fairly
sure it's because of this line:
lRow = wksFound.Cells(Rows.Count, 1).End(xlUp).Row + 1

What I want to do is place the result of my initial search in row 1
then any further search results in row 2, then row 3 etc etc

Hoping someone could offer some assistance.

Kind Regards,
Dean


Public Sub vbaCopyToAnotherSheet()
Dim rCell As Excel.Range
Dim rRow As Excel.Range
Dim wksFound As Excel.Worksheet
Dim wksData As Excel.Worksheet

Dim szLookupVal As String
Dim szRowAddy As String

Dim lRow As Long


Set wksFound = Sheets("Found") 'Sheet that gets the copied data
Set wksData = Sheets("Database") 'Sheet that contains the data to
search


lRow = wksFound.Cells(Rows.Count, 1).End(xlUp).Row + 1

szLookupVal = InputBox("What are you searching for", "Search-Box",
"")
If Len(szLookupVal) = 0 Then Exit Sub

With wksData.Cells

Set rCell = .Find(szLookupVal, , , , , , False)
If Not rCell Is Nothing Then

szRowAddy = rCell.Address

Set rRow = rCell

Do

Set rCell = .FindNext(rCell)

Set rRow = Application.Union(rRow, rCell)

rRow.EntireRow.Copy wksFound.Cells(lRow, 1)

Loop While Not rCell Is Nothing And rCell.Address < szRowAddy

End If
End With

Set rCell = Nothing
Set rRow = Nothing
Set wksFound = Nothing
Set wksData = Nothing
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default An Easy Mod For Sure

lRow = wksFound.Cells(Rows.Count, 1).End(xlUp).Row + 1
If isempty(wksfound.Cells(1,1)) and lRow = 2 then lRow = 1

--
Regards,
Tom Ogilvy



"Dean" wrote:

Hi, I'm having a bit of trouble with this code and would appreciate
some help.

It essentailly is working however when it copies the data to the
"Found" page it always leaves the first row "1" blank and I am fairly
sure it's because of this line:
lRow = wksFound.Cells(Rows.Count, 1).End(xlUp).Row + 1

What I want to do is place the result of my initial search in row 1
then any further search results in row 2, then row 3 etc etc

Hoping someone could offer some assistance.

Kind Regards,
Dean


Public Sub vbaCopyToAnotherSheet()
Dim rCell As Excel.Range
Dim rRow As Excel.Range
Dim wksFound As Excel.Worksheet
Dim wksData As Excel.Worksheet

Dim szLookupVal As String
Dim szRowAddy As String

Dim lRow As Long


Set wksFound = Sheets("Found") 'Sheet that gets the copied data
Set wksData = Sheets("Database") 'Sheet that contains the data to
search


lRow = wksFound.Cells(Rows.Count, 1).End(xlUp).Row + 1

szLookupVal = InputBox("What are you searching for", "Search-Box",
"")
If Len(szLookupVal) = 0 Then Exit Sub

With wksData.Cells

Set rCell = .Find(szLookupVal, , , , , , False)
If Not rCell Is Nothing Then

szRowAddy = rCell.Address

Set rRow = rCell

Do

Set rCell = .FindNext(rCell)

Set rRow = Application.Union(rRow, rCell)

rRow.EntireRow.Copy wksFound.Cells(lRow, 1)

Loop While Not rCell Is Nothing And rCell.Address < szRowAddy

End If
End With

Set rCell = Nothing
Set rRow = Nothing
Set wksFound = Nothing
Set wksData = Nothing
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default An Easy Mod For Sure

Excellent, that did the trick. Thanks again.

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
Easy one..not for me.. Rogie Excel Discussion (Misc queries) 1 February 13th 07 10:23 AM
How to sum in an easy way? [email protected] Excel Discussion (Misc queries) 7 April 20th 06 02:38 PM
Very easy I'm sure themax16 Excel Discussion (Misc queries) 2 October 21st 05 04:02 PM
probably easy but.... obion Excel Worksheet Functions 3 October 7th 05 07:08 PM
new user with easy question? not easy for me speakeztruth New Users to Excel 5 June 3rd 05 09:40 PM


All times are GMT +1. The time now is 01:10 PM.

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"