Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Code does not error but no copy either

Code does not work and does not error.

Find a value in the Sheets("Sheet1").Range("A1:H11") and copy the values in columns I and K of the "found string" row to Workbooks("Book2").Sheets("Sheet1") Range("B15") and Range("D15") with next copies below the last.

Also, I know there is a cleaner way than the .Range("B100").End(xlUp).Offset(1, 0)
but I cannot find one in my archives.

Thanks,
Howard

Option Explicit

Sub Find_First()
Dim FindString As String
Dim Rng As Range
Dim i As Long
Dim RngI As String
Dim RngK As String

FindString = InputBox("Enter a Search value")
If Trim(FindString) < "" Then
With Sheets("Sheet1").Range("A1:H11")
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
i = Rng.Column

RngI = ActiveCell.Offset(0, 9 - i)
RngK = ActiveCell.Offset(0, 11 - i)

Workbooks("Book2").Sheets("Sheet1").Range("B100"). End(xlUp).Offset(1, 0) = RngI
Workbooks("Book2").Sheets("Sheet1").Range("D100"). End(xlUp).Offset(1, 0) = RngK

Else
MsgBox "Nothing found"
End If

End With

End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Code does not error but no copy either

Hi Howard,

Am Mon, 15 Jul 2013 23:53:19 -0700 (PDT) schrieb Howard:

Code does not work and does not error.

Find a value in the Sheets("Sheet1").Range("A1:H11") and copy the values in columns I and K of the "found string" row to Workbooks("Book2").Sheets("Sheet1") Range("B15") and Range("D15") with next copies below the last.

Also, I know there is a cleaner way than the .Range("B100").End(xlUp).Offset(1, 0)
but I cannot find one in my archives.


try:

If Not Rng Is Nothing Then
RngI = .Cells(Rng.Row, "I")
RngK = .Cells(Rng.Row, "K")
With Workbooks("Book2").Sheets("Sheet1")
Set LRow = .Cells(.Rows.Count, "B").End(xlUp)(2)
LRow = RngI
LRow.Offset(, 2) = RngK
End With
Else
MsgBox "Nothing found"
End If


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Code does not error but no copy either

On Tuesday, July 16, 2013 12:26:21 AM UTC-7, Claus Busch wrote:
Hi Howard,



Am Mon, 15 Jul 2013 23:53:19 -0700 (PDT) schrieb Howard:



Code does not work and does not error.




Find a value in the Sheets("Sheet1").Range("A1:H11") and copy the values in columns I and K of the "found string" row to Workbooks("Book2").Sheets("Sheet1") Range("B15") and Range("D15") with next copies below the last.




Also, I know there is a cleaner way than the .Range("B100").End(xlUp).Offset(1, 0)


but I cannot find one in my archives.




try:



If Not Rng Is Nothing Then

RngI = .Cells(Rng.Row, "I")

RngK = .Cells(Rng.Row, "K")

With Workbooks("Book2").Sheets("Sheet1")

Set LRow = .Cells(.Rows.Count, "B").End(xlUp)(2)

LRow = RngI

LRow.Offset(, 2) = RngK

End With

Else

MsgBox "Nothing found"

End If





Regards

Claus B.


Much cleaner.
Thanks, Claus.

Regards,
Howard
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Code does not error but no copy either

Hi Howard,

Am Tue, 16 Jul 2013 00:59:33 -0700 (PDT) schrieb Howard:

Much cleaner.


but does it work?


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Code does not error but no copy either

On Tuesday, July 16, 2013 1:03:30 AM UTC-7, Claus Busch wrote:
Hi Howard,



Am Tue, 16 Jul 2013 00:59:33 -0700 (PDT) schrieb Howard:



Much cleaner.




but does it work?





Regards

Claus B.

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


Yes, indeed, works fine. However, it had a subscript out of range error and that lead me to investigate and see that my original code was actually working except I have Book2 as the copy TO and It should have been Book3.

So it would copy back to the same sheet as the copy FROM, while all the time I was looking at book3 for the results and not getting any.

You can fix code, but you can't fix stupid.<g

Thanks Claus.

Regards,
Howard






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
(Error 1004) Object Defined Error ...simple code Robert Crandal Excel Programming 1 January 12th 10 10:31 PM
copy and insert throwing error- help in code req dee Excel Discussion (Misc queries) 8 March 6th 08 09:57 PM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM
Code to copy range vs Copy Entire Worksheet - can't figure it out Mike Taylor Excel Programming 1 April 15th 04 08:34 PM


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