Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Macro to look for where vLookup has a result then paste value

I'm looking for a macro to look for cells in a column where a vlookup formula
has returned a value other than blank, and then paste the result in that same
cell thus removing the formula. If the value is blank then I want to keep the
formula.
=IF(V6="","-",VLOOKUP(V6,'[AMS Crew list.xls]Crew Info table'!$A:$E,2,FALSE))
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro to look for where vLookup has a result then paste value

Dim myRng as range
dim myCell as range

with worksheets("SomeSheetNameHere")
set myrng = .range("B2",.cells(.rows.count,"B").end(xlup))
end with

for each mycell in myrng.cells
if mycell.value = "" _
or mycell.value = "-" then
'do nothing
else
mycell.value = mycell.value
end if
next mycell

If figured you'd want to keep the hyphens and the blanks.

I wonder what you want to happen if 0 is returned because the sending cell is
empty?



Aposto wrote:

I'm looking for a macro to look for cells in a column where a vlookup formula
has returned a value other than blank, and then paste the result in that same
cell thus removing the formula. If the value is blank then I want to keep the
formula.
=IF(V6="","-",VLOOKUP(V6,'[AMS Crew list.xls]Crew Info table'!$A:$E,2,FALSE))


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Macro to look for where vLookup has a result then paste value

This example uses column H

Sub looker_upper()
Dim v As Variant
Set rr = Intersect(ActiveSheet.UsedRange.SpecialCells(xlCel lTypeFormulas),
Range("H:H"))
s = "VLOOKUP"
For Each r In rr
f = r.Formula
v = r.Value
If InStr(f, s) < 0 Then
If v < "" Then
r.Value = r.Value
End If
End If
Next
End Sub

--
Gary''s Student - gsnu200781


"Aposto" wrote:

I'm looking for a macro to look for cells in a column where a vlookup formula
has returned a value other than blank, and then paste the result in that same
cell thus removing the formula. If the value is blank then I want to keep the
formula.
=IF(V6="","-",VLOOKUP(V6,'[AMS Crew list.xls]Crew Info table'!$A:$E,2,FALSE))

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Macro to look for where vLookup has a result then paste value

Both macro work but I get a "Type mismatch" error and I belive it is because
the formula is returning an error #N/A. How would you tell the macro to leave
the formula in if an error is the value.

"Dave Peterson" wrote:

Dim myRng as range
dim myCell as range

with worksheets("SomeSheetNameHere")
set myrng = .range("B2",.cells(.rows.count,"B").end(xlup))
end with

for each mycell in myrng.cells
if mycell.value = "" _
or mycell.value = "-" then
'do nothing
else
mycell.value = mycell.value
end if
next mycell

If figured you'd want to keep the hyphens and the blanks.

I wonder what you want to happen if 0 is returned because the sending cell is
empty?



Aposto wrote:

I'm looking for a macro to look for cells in a column where a vlookup formula
has returned a value other than blank, and then paste the result in that same
cell thus removing the formula. If the value is blank then I want to keep the
formula.
=IF(V6="","-",VLOOKUP(V6,'[AMS Crew list.xls]Crew Info table'!$A:$E,2,FALSE))


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro to look for where vLookup has a result then paste value

Dim myRng as range
dim myCell as range

with worksheets("SomeSheetNameHere")
set myrng = .range("B2",.cells(.rows.count,"B").end(xlup))
end with

for each mycell in myrng.cells
if iserror(mycell.value) then
'do nothing
else
if mycell.value = "" _
or mycell.value = "-" then
'do nothing
else
mycell.value = mycell.value
end if
end if
next mycell

Aposto wrote:

Both macro work but I get a "Type mismatch" error and I belive it is because
the formula is returning an error #N/A. How would you tell the macro to leave
the formula in if an error is the value.

"Dave Peterson" wrote:

Dim myRng as range
dim myCell as range

with worksheets("SomeSheetNameHere")
set myrng = .range("B2",.cells(.rows.count,"B").end(xlup))
end with

for each mycell in myrng.cells
if mycell.value = "" _
or mycell.value = "-" then
'do nothing
else
mycell.value = mycell.value
end if
next mycell

If figured you'd want to keep the hyphens and the blanks.

I wonder what you want to happen if 0 is returned because the sending cell is
empty?



Aposto wrote:

I'm looking for a macro to look for cells in a column where a vlookup formula
has returned a value other than blank, and then paste the result in that same
cell thus removing the formula. If the value is blank then I want to keep the
formula.
=IF(V6="","-",VLOOKUP(V6,'[AMS Crew list.xls]Crew Info table'!$A:$E,2,FALSE))


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Macro to look for where vLookup has a result then paste value

Bingo works like a charm. Thanks to both you a Gary for your assistance!

"Dave Peterson" wrote:

Dim myRng as range
dim myCell as range

with worksheets("SomeSheetNameHere")
set myrng = .range("B2",.cells(.rows.count,"B").end(xlup))
end with

for each mycell in myrng.cells
if iserror(mycell.value) then
'do nothing
else
if mycell.value = "" _
or mycell.value = "-" then
'do nothing
else
mycell.value = mycell.value
end if
end if
next mycell

Aposto wrote:

Both macro work but I get a "Type mismatch" error and I belive it is because
the formula is returning an error #N/A. How would you tell the macro to leave
the formula in if an error is the value.

"Dave Peterson" wrote:

Dim myRng as range
dim myCell as range

with worksheets("SomeSheetNameHere")
set myrng = .range("B2",.cells(.rows.count,"B").end(xlup))
end with

for each mycell in myrng.cells
if mycell.value = "" _
or mycell.value = "-" then
'do nothing
else
mycell.value = mycell.value
end if
next mycell

If figured you'd want to keep the hyphens and the blanks.

I wonder what you want to happen if 0 is returned because the sending cell is
empty?



Aposto wrote:

I'm looking for a macro to look for cells in a column where a vlookup formula
has returned a value other than blank, and then paste the result in that same
cell thus removing the formula. If the value is blank then I want to keep the
formula.
=IF(V6="","-",VLOOKUP(V6,'[AMS Crew list.xls]Crew Info table'!$A:$E,2,FALSE))

--

Dave Peterson


--

Dave Peterson

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
vlookup untill a vaule is found then automaticaly paste the result Aposto Excel Worksheet Functions 1 April 30th 08 04:42 PM
Vlookup in vlookup - taking the result as array name SupperDuck Excel Worksheet Functions 2 June 2nd 07 11:05 AM
vlookup shows result one cell above the expected result Marie Excel Worksheet Functions 7 November 14th 06 02:52 AM
vlookup based on random result returns incorrect result rickat Excel Worksheet Functions 1 December 6th 05 01:16 PM
Copy Paste of Formula Produces Incorrect Result JLa Excel Discussion (Misc queries) 1 May 17th 05 06:56 PM


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