View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ken[_2_] Ken[_2_] is offline
external usenet poster
 
Posts: 45
Default Correct syntax for IF, Then in a macro

On Jun 21, 11:20*am, Ken wrote:
On Jun 21, 11:12*am, Ken wrote:





Thanks Mike and Per....I really appreciate your help.....looking at
your suggestions, here is what I came up with that seems so far to do
the trick:
Sub SearchForString2()


* * Dim LSearchRow As Integer
* * Dim LCopyToRow As Integer
* * Dim LSearchValue As String


* * On Error GoTo Err_Execute


* * LSearchValue = InputBox("Please enter a value to search for.DO NOT
hit OK or CANCEL before entering a date, entire log will transfer!!!",
"Enter value")


* * 'Start search in row 2
* * LSearchRow = 2


* * 'Start copying data to row 4 in WeeklyDueLog (row counter
variable)
* * LCopyToRow = 4


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


* * 'If value in column J = LSearchValue, and column O or Q are empty,
copy entire row to Sheet2


* * If Cells(LSearchRow, "J").Value = LSearchValue And
Cells(LSearchRow, "O").Value = "" And Cells(LSearchRow, "Q").Value =
"" Then
* * * * * * 'Select row in JobLogEntry to copy
* * * * * * Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow))..Select
* * * * * * Selection.Copy


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


* * * * * * 'Move counter to next row
* * * * * * LCopyToRow = LCopyToRow + 1


* * * * * * 'Go back to JobLogEntry to continue searching
* * * * * * Sheets("JobLogEntry").Select


* * * * End If


* * * * LSearchRow = LSearchRow + 1


* * Wend


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


* * MsgBox "All matching data has been copied."


* * Exit Sub


Err_Execute:
* * MsgBox "An error occurred."


End Sub


The only question I have right now, is how would I disable the OK and
Cancel button on my input box until an input is actually entered?? If
I hit either one before entering the search date, the entire log
(5000+ entries) transfers....sort of like a "wildcard" entry...if you
have any suggestions, I am deeply grateful...if not, I am still
thankful for your help!
Ken


Correction on the last statement, all entries with no due date are
found, and that in itself is OK.....Thanks guys for your help....Ken- Hide quoted text -

- Show quoted text -


I only have one problem, though, the dates in the copied row show up
as it's numeric equivalent and cannot be changed, even with all the
usual cell formatting tools....any ideas on what is happening? Can it
be changed in the macro??
Ken