Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default lookup,copy, paste macro??

I have searched Google and the groups for this, but unable to find.

Need a macro to take a entered value in any cell on Sheet 1, column A,
look up that value on Sheet 2, column A, go one row over to col. B,
copy the cell, then paste it into Sheet 1, column B, next to the
entered value.
Just like Vlookup, only copypaste .
Need to paste the cell contents, not just values.


any and all help GREATLY appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default lookup,copy, paste macro??

Hi Hugh

If I've understood you correctly then this should do it ...

Sub doIt()

' first get your sheet1 column A lookup value from whichever rowNumber .. let's make it 4
rownumber = 4
lookupValueA = Sheets("sheet1").Cells(rownumber, 1)

'now iterate through your list on sheet2 (assume list ends with first blank cell encountered)
rowPointer = 1
While Sheets("sheet2").Cells(rowPointer, 1) < ""
If Sheets("sheet2").Cells(rowPointer, 1) = lookupValueA Then
lookupValueB = Sheets("sheet2").Cells(rowPointer, 2) ' get adjacent value in column B
End If
rowPointer = rowPointer + 1
Wend

'now put that value in column B in sheet1
Sheets("sheet1").Cells(rownumber, 2) = lookupValueB

' bingo ... it's inefficient in that it looks through the whole of Sheet2's values ... but what the heck!
' btw it assumes no duplication of values in your list sheet2

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default lookup,copy, paste macro??

I would have thought that contents meant values, but if you mean formatting,
too, how about something like this:

Option Explicit
Sub testme()

Dim res As Variant
Dim wks As Worksheet
Dim lookupWks As Worksheet
Dim lookupRng As Range
Dim myCell As Range
Dim myRng As Range

Set wks = Worksheets("sheet1")
Set lookupWks = Worksheets("sheet2")

With lookupWks
Set lookupRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

With wks
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
For Each myCell In myRng.Cells
If IsEmpty(myCell) Then
'do nothing
Else
res = Application.Match(myCell.Value, lookupRng, 0)
If IsError(res) Then
'no match-what should be done?
Else
lookupRng(res).Offset(0, 1).Copy _
myCell.Offset(0, 1)
End If
End If
Next myCell
End With

End Sub


I used .offset(0,1) in both spots, but you could change each of them to what you
want.


Hugh Askew wrote:

I have searched Google and the groups for this, but unable to find.

Need a macro to take a entered value in any cell on Sheet 1, column A,
look up that value on Sheet 2, column A, go one row over to col. B,
copy the cell, then paste it into Sheet 1, column B, next to the
entered value.
Just like Vlookup, only copypaste .
Need to paste the cell contents, not just values.

any and all help GREATLY appreciated.


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default lookup,copy, paste macro??

Dave, many,many gracious thanks! EXACTLY what was needed!!!



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Copy and Paste Macro ABelect Excel Discussion (Misc queries) 1 April 15th 10 11:24 PM
copy and paste using macro kate Excel Discussion (Misc queries) 3 May 22nd 07 07:41 PM
Copy Paste macro GWB Direct Excel Discussion (Misc queries) 2 May 9th 05 03:31 PM
Macro Copy/Paste Help esi Excel Programming 2 October 8th 03 11:15 AM
copy/paste macro PLN Excel Programming 2 July 21st 03 10:15 PM


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