Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
HEY HEY is offline
external usenet poster
 
Posts: 14
Default macro cut and paste

Below what you gave me last week doesnt work. It doesnt like the last end if

Thank

sub foo(
dim look_rng as rang
dim source_rng as rang
dim target_rng as rang
dim ret_valu
with activeshee
set look_rng = .range("A1"
set target_rng = .rnage("B1"
set source_rng = .range("C1:D100"
end wit
ret_value=application.vlookup(look_rng,source_rng, 2,0
if iserror(ret_value) the
ret_value="
end i
target_rng=ret_valu
end i

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default macro cut and paste

Looks like that End If should be End Sub.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"hey" wrote in message
...
Below what you gave me last week doesnt work. It doesnt like the last

end if?

Thanks


sub foo()
dim look_rng as range
dim source_rng as range
dim target_rng as range
dim ret_value
with activesheet
set look_rng = .range("A1")
set target_rng = .rnage("B1")
set source_rng = .range("C1:D100")
end with
ret_value=application.vlookup(look_rng,source_rng, 2,0)
if iserror(ret_value) then
ret_value=""
end if
target_rng=ret_value
end if



  #3   Report Post  
Posted to microsoft.public.excel.programming
HEY HEY is offline
external usenet poster
 
Posts: 14
Default macro cut and paste

Tried that, doesnt work either!
  #4   Report Post  
Posted to microsoft.public.excel.programming
HEY HEY is offline
external usenet poster
 
Posts: 14
Default macro cut and paste

OK, end sub does work if I correct the misspelling of the word rnage to range
But, this isnt quit what I want to do. Close but not quit. I would like it to find the lookup but then cut and paste it into cell b1 so that all formats come with. Dont ask why it would be a long explaination. Is it possible

Thanks for any help.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default macro cut and paste

One way:

Public Sub test()
Dim rFound As Range
Set rFound = Columns(3).Find( _
What:=Range("A1").Value, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not rFound Is Nothing Then _
rFound.Offset(0, 1).Copy Destination:=Range("B1")
End Sub



In article ,
hey wrote:

OK, end sub does work if I correct the misspelling of the word rnage to
range.
But, this isnt quit what I want to do. Close but not quit. I would like it to
find the lookup but then cut and paste it into cell b1 so that all formats
come with. Dont ask why it would be a long explaination. Is it possible?

Thanks for any help.



  #6   Report Post  
Posted to microsoft.public.excel.programming
HEY HEY is offline
external usenet poster
 
Posts: 14
Default macro cut and paste

Now you confused me, is this exactly what I must copy and insert? Where are the ranges I had before with the lookup

Thanks
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default macro cut and paste

Sub foo()
Dim look_rng As Range
Dim source_rng As Range
Dim target_rng As Range
Dim rFound As Range

With ActiveSheet
Set look_rng = .Range("A1")
Set target_rng = .Range("B1")
Set source_rng = .Range("C1:C100")
End With
Set rFound = source_rng.Find( _
What:=look_rng.Value, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not rFound Is Nothing Then
rFound.Offset(0, 1).Copy Destination:=target_rng
rFound.Resize(1, 2).Delete Shift:=xlShiftUp
End If
End Sub

The above deletes the cells in columns C and D for the row where the value
was found.

If you only want the cell in column D deleted (this is the cell copied)
rFound.Offset(0, 1).Delete Shift:=xlShiftUp

If youonly want the cell in column C deleted (this is the cell found)
rFound.Delete Shift:=xlShiftUp

--
Regards,
Tom Ogilvy


"hey" wrote in message
...
Now you confused me, is this exactly what I must copy and insert? Where

are the ranges I had before with the lookup?

Thanks



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default macro cut and paste

Yes - that's what you should enter. I assumed you were looking up over
all of column C. If you'd rather have just C1:C100 as Frank had, instead
of

Set rFound = Columns(3).Find( _

use

Set rFound = Range("C1:C100").Find( _


Since you didn't reply to a previous post, I can't tell if those are the
ranges you had before - I assumed Frank used your ranges.

In article ,
hey wrote:

Now you confused me, is this exactly what I must copy and insert? Where are
the ranges I had before with the lookup?

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default macro cut and paste

The end should have

End Su

--
Message posted from http://www.ExcelForum.com

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default macro cut and paste

Frank never tested the code he posted - there are a couple of errors.

Try:

Public Sub foo()
Dim look_rng As Range
Dim source_rng As Range
Dim target_rng As Range
Dim ret_Value As Variant
With ActiveSheet
Set look_rng = .Range("A1")
Set target_rng = .Range("B1")
Set source_rng = .Range("C1:D100")
End With
ret_Value = Application.VLookup(look_rng, source_rng, 2, 0)
If IsError(ret_Value) Then ret_Value = ""
target_rng = ret_Value
End Sub


In article ,
hey wrote:

Below what you gave me last week doesnt work. It doesnt like the last end
if?

Thanks


sub foo()
dim look_rng as range
dim source_rng as range
dim target_rng as range
dim ret_value
with activesheet
set look_rng = .range("A1")
set target_rng = .rnage("B1")
set source_rng = .range("C1:D100")
end with
ret_value=application.vlookup(look_rng,source_rng, 2,0)
if iserror(ret_value) then
ret_value=""
end if
target_rng=ret_value
end if



  #11   Report Post  
Posted to microsoft.public.excel.programming
HEY HEY is offline
external usenet poster
 
Posts: 14
Default macro cut and paste

see my comments above gh1984
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
Cut and Paste Macro M.A.Tyler Excel Discussion (Misc queries) 3 April 28th 07 02:50 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 1 June 11th 05 12:44 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 0 June 10th 05 03:38 PM
Macro to Paste to specific line, and continue to Paste each time on next row not over tomkarakowski[_2_] Excel Programming 1 May 28th 04 06:50 PM
Macro to Copy/Paste then Paste to Next Line tomkarakowski Excel Programming 1 May 28th 04 01:19 AM


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