LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default paste row into Sheet2 in next row

Hi All,
I found code and tried to change it to make it fit me worksheet. I am
using a inputbox to get a date range for report selection. The following
code highlights and copies the first matchof my criteria set then I get the
Err_Execute message in the sheet that I am copying to. Can someone tell me
what is wrong with my code? Thanks
Kim

Sub SearchForString()

Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim LSearchValue As String
Dim LSearchValue2 As String
Dim checkDate As Boolean
Dim checkDate2 As Boolean

On Error GoTo Err_Execute

checkDate = False

Do

LSearchValue = InputBox("Enter Start Date 'mm/dd/yyyy'.", "Enter value")

If IsDate(LSearchValue) Then
dt = CDate(LSearchValue)
checkDate = True
Else
MsgBox ("You provided an invalid Start Date value")
LSearchValue = InputBox("Enter Start Date 'mm/dd/yyyy'.", "Enter
value")
checkDate = False
End If

Loop Until checkDate = True

checkDate2 = False
LSearchValue2 = InputBox("Enter End Date 'mm/dd/yyyy'.", "Enter value")
Do

If IsDate(LSearchValue2) Then
dt2 = CDate(LSearchValue2)
checkDate2 = True
Else
MsgBox ("You provided an invalid End Date value")
LSearchValue2 = InputBox("Enter End Date 'mm/dd/yyyy'.", "Enter
value")
checkDate2 = False
End If

Loop Until checkDate2 = True

'Start search in row 6
LSearchRow = 6

'Start copying data to row 2 in Sheet2 (row counter variable)
LCopyToRow = 2

While Len(Range("A" & CStr(LSearchRow)).Value) 0

'If value in column E = LSearchValue, copy entire row to Sheet2
If Range("J" & CStr(LSearchRow)).Value = dt And Range("J" &
CStr(LSearchRow)).Value <= dt2 Then

'Select row in Sheet1 to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy

'Paste row into Sheet2 in next row
Sheets("Results").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste

'Move counter to next row
LCopyToRow = LCopyToRow + 1

'Go back to Sheet1 to continue searching
Sheets("Report").Select
Else
Sheets("Report").Select
End If

LSearchRow = LSearchRow + 1

Wend

'Position on cell A3
Application.CutCopyMode = False
Range("A3").Select

MsgBox "All matching data has been copied to the Report tab."

Exit Sub

Err_Execute:
MsgBox "An error occurred."

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
How to copy from sheet1 then paste special transpose to sheet2,3,4 Christine Excel Discussion (Misc queries) 2 July 22nd 09 09:50 PM
copy data from sheet2 to sheet1 when sheet2 has variable # of rows Anne Excel Discussion (Misc queries) 6 February 27th 09 09:48 PM
macro to print sheet2 without open sheet2 ramzi Excel Discussion (Misc queries) 1 January 28th 09 12:07 PM
Macro to Copy data from a list in sheet1 and paste into sheet2 Michael Excel Discussion (Misc queries) 3 April 23rd 08 06:52 PM
how do copy "sheet1!A1+1 in sheet2 to sheet 3 and get "sheet2!A1+ Dany Excel Discussion (Misc queries) 5 April 16th 07 03:27 AM


All times are GMT +1. The time now is 08:29 AM.

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"