Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 226
Default Quick Question - Edit Macro

Hello,

Can you help me to set this macro up so it works between 2 workbooks vs.
just working on the same sheet viewing different columns?

Im looking for Sheet1 in Workbook A to look for a Match in Sheet2 Workbook
B. Ive filled in the ranges as they would appear in each of the Workbooks.
Range(€œE2:E100€) is the range in Workbook A looking to match Range(€œA2€A100)
in Workbook B. If match is found, Workbook A Range (€œB2:B100€) would copy
cell values to destination Workbook B Range(€œ€C2:C100€).

Appreciate any help you can provide.

Thanks - Roger

Sub TestCopyFormat()

Dim Cell As Range
Dim Cindex As Integer
On Error GoTo errorhandler
Application.DisplayAlerts = False
With Worksheets("Sheet1")
For Each Cell In Range("E2:E100")
Cindex = WorksheetFunction.Match(Cell.Text, .Range("A2:A100"), 0)
.Range("B2:B100").Cells(Cindex, 1).Copy _
Destination:=Range("C2:C100").Cells(Cindex, 1)
Next Cell
End With
errorhandler:
Application.DisplayAlerts = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Quick Question - Edit Macro

I _think_ this does what you want.

Dim WkbkARng as range
dim WkbkBRng as range
dim myCell as range
dim res as variant 'could be a number or an error

set wkbkARng = workbooks("workbookA.xls").worksheets("sheet1").ra nge("E2:e100")
set wkbkBRng = workbooks("workbookB.xls").worksheets("sheet2").ra nge("a2:a100")

for each mycell in wkbkarng.cells
res = application.match(mycell.value,wkbkbrng,0)
if iserror(res) then
'no match, do nothing
else
mycell.offset(0,1).copy _
destination:=wkbkbrng(res)

'or just to bring back the value
'wkbkbrng(res).offset(0,1).value = mycell.offset(0,1).value
end if
next mycell


Untested, uncompiled--watch for typos.

Roger wrote:

Hello,

Can you help me to set this macro up so it works between 2 workbooks vs.
just working on the same sheet viewing different columns?

Im looking for Sheet1 in Workbook A to look for a Match in Sheet2 Workbook
B. Ive filled in the ranges as they would appear in each of the Workbooks.
Range(€œE2:E100€) is the range in Workbook A looking to match Range(€œA2€A100)
in Workbook B. If match is found, Workbook A Range (€œB2:B100€) would copy
cell values to destination Workbook B Range(€œ€C2:C100€).

Appreciate any help you can provide.

Thanks - Roger

Sub TestCopyFormat()

Dim Cell As Range
Dim Cindex As Integer
On Error GoTo errorhandler
Application.DisplayAlerts = False
With Worksheets("Sheet1")
For Each Cell In Range("E2:E100")
Cindex = WorksheetFunction.Match(Cell.Text, .Range("A2:A100"), 0)
.Range("B2:B100").Cells(Cindex, 1).Copy _
Destination:=Range("C2:C100").Cells(Cindex, 1)
Next Cell
End With
errorhandler:
Application.DisplayAlerts = True
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 226
Default Quick Question - Edit Macro

Hi Dave,

Thank you so much for answering this- it's really been giving me a sharp
pain in the backside.

You noted that I could bring back the value by swapping the line of code as
noted below. The problem is once I swap, I get an error and I'm not sure
what I'm doing wrong.

Thanks again for your review - Roger

myCell.Offset(0, 1).Copy _
Destination:=WkbkRng(res) <<<< tried to replace as shown below


myCell.Offset(0, 1).Copy
Destination:=wkbkbrng(res).offset(0,1).value = mycell.offset(0,1).value
<<< received error with above

"Roger" wrote:

Hello,

Can you help me to set this macro up so it works between 2 workbooks vs.
just working on the same sheet viewing different columns?

Im looking for Sheet1 in Workbook A to look for a Match in Sheet2 Workbook
B. Ive filled in the ranges as they would appear in each of the Workbooks.
Range(€œE2:E100€) is the range in Workbook A looking to match Range(€œA2€A100)
in Workbook B. If match is found, Workbook A Range (€œB2:B100€) would copy
cell values to destination Workbook B Range(€œ€C2:C100€).

Appreciate any help you can provide.

Thanks - Roger

Sub TestCopyFormat()

Dim Cell As Range
Dim Cindex As Integer
On Error GoTo errorhandler
Application.DisplayAlerts = False
With Worksheets("Sheet1")
For Each Cell In Range("E2:E100")
Cindex = WorksheetFunction.Match(Cell.Text, .Range("A2:A100"), 0)
.Range("B2:B100").Cells(Cindex, 1).Copy _
Destination:=Range("C2:C100").Cells(Cindex, 1)
Next Cell
End With
errorhandler:
Application.DisplayAlerts = True
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Quick Question - Edit Macro

What error did you get?

And maybe you wanted this:

mycell.offset(0,1).copy _
destination:=wkbkbrng(res).offset(0,1)

Did you want to bring back the column to the right of the matching cell and
place it in the cell to the right of the original cell?

Roger wrote:

Hi Dave,

Thank you so much for answering this- it's really been giving me a sharp
pain in the backside.

You noted that I could bring back the value by swapping the line of code as
noted below. The problem is once I swap, I get an error and I'm not sure
what I'm doing wrong.

Thanks again for your review - Roger

myCell.Offset(0, 1).Copy _
Destination:=WkbkRng(res) <<<< tried to replace as shown below

myCell.Offset(0, 1).Copy
Destination:=wkbkbrng(res).offset(0,1).value = mycell.offset(0,1).value
<<< received error with above

"Roger" wrote:

Hello,

Can you help me to set this macro up so it works between 2 workbooks vs.
just working on the same sheet viewing different columns?

Im looking for Sheet1 in Workbook A to look for a Match in Sheet2 Workbook
B. Ive filled in the ranges as they would appear in each of the Workbooks.
Range(€œE2:E100€) is the range in Workbook A looking to match Range(€œA2€A100)
in Workbook B. If match is found, Workbook A Range (€œB2:B100€) would copy
cell values to destination Workbook B Range(€œ€C2:C100€).

Appreciate any help you can provide.

Thanks - Roger

Sub TestCopyFormat()

Dim Cell As Range
Dim Cindex As Integer
On Error GoTo errorhandler
Application.DisplayAlerts = False
With Worksheets("Sheet1")
For Each Cell In Range("E2:E100")
Cindex = WorksheetFunction.Match(Cell.Text, .Range("A2:A100"), 0)
.Range("B2:B100").Cells(Cindex, 1).Copy _
Destination:=Range("C2:C100").Cells(Cindex, 1)
Next Cell
End With
errorhandler:
Application.DisplayAlerts = True
End Sub


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 226
Default Quick Question - Edit Macro

That is exactly what I wanted and it is now working flawlessly.

Thank you for your help and you rock!

Roger



"Dave Peterson" wrote:

What error did you get?

And maybe you wanted this:

mycell.offset(0,1).copy _
destination:=wkbkbrng(res).offset(0,1)

Did you want to bring back the column to the right of the matching cell and
place it in the cell to the right of the original cell?

Roger wrote:

Hi Dave,

Thank you so much for answering this- it's really been giving me a sharp
pain in the backside.

You noted that I could bring back the value by swapping the line of code as
noted below. The problem is once I swap, I get an error and I'm not sure
what I'm doing wrong.

Thanks again for your review - Roger

myCell.Offset(0, 1).Copy _
Destination:=WkbkRng(res) <<<< tried to replace as shown below

myCell.Offset(0, 1).Copy
Destination:=wkbkbrng(res).offset(0,1).value = mycell.offset(0,1).value
<<< received error with above

"Roger" wrote:

Hello,

Can you help me to set this macro up so it works between 2 workbooks vs.
just working on the same sheet viewing different columns?

I€„¢m looking for Sheet1 in Workbook A to look for a Match in Sheet2 Workbook
B. I€„¢ve filled in the ranges as they would appear in each of the Workbooks.
Range(€œE2:E100€Â) is the range in Workbook A looking to match Range(€œA2€ÂA100)
in Workbook B. If match is found, Workbook A Range (€œB2:B100€Â) would copy
cell values to destination Workbook B Range(€œ€ÂC2:C100€Â).

Appreciate any help you can provide.

Thanks - Roger

Sub TestCopyFormat()

Dim Cell As Range
Dim Cindex As Integer
On Error GoTo errorhandler
Application.DisplayAlerts = False
With Worksheets("Sheet1")
For Each Cell In Range("E2:E100")
Cindex = WorksheetFunction.Match(Cell.Text, .Range("A2:A100"), 0)
.Range("B2:B100").Cells(Cindex, 1).Copy _
Destination:=Range("C2:C100").Cells(Cindex, 1)
Next Cell
End With
errorhandler:
Application.DisplayAlerts = True
End Sub


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Quick Question - Edit Macro

Glad you got it working--and sorry about the original typo.

Roger wrote:

That is exactly what I wanted and it is now working flawlessly.

Thank you for your help and you rock!

Roger

"Dave Peterson" wrote:

What error did you get?

And maybe you wanted this:

mycell.offset(0,1).copy _
destination:=wkbkbrng(res).offset(0,1)

Did you want to bring back the column to the right of the matching cell and
place it in the cell to the right of the original cell?

Roger wrote:

Hi Dave,

Thank you so much for answering this- it's really been giving me a sharp
pain in the backside.

You noted that I could bring back the value by swapping the line of code as
noted below. The problem is once I swap, I get an error and I'm not sure
what I'm doing wrong.

Thanks again for your review - Roger

myCell.Offset(0, 1).Copy _
Destination:=WkbkRng(res) <<<< tried to replace as shown below

myCell.Offset(0, 1).Copy
Destination:=wkbkbrng(res).offset(0,1).value = mycell.offset(0,1).value
<<< received error with above

"Roger" wrote:

Hello,

Can you help me to set this macro up so it works between 2 workbooks vs.
just working on the same sheet viewing different columns?

I€„¢m looking for Sheet1 in Workbook A to look for a Match in Sheet2 Workbook
B. I€„¢ve filled in the ranges as they would appear in each of the Workbooks.
Range(€œE2:E100€Â) is the range in Workbook A looking to match Range(€œA2€ÂA100)
in Workbook B. If match is found, Workbook A Range (€œB2:B100€Â) would copy
cell values to destination Workbook B Range(€œ€ÂC2:C100€Â).

Appreciate any help you can provide.

Thanks - Roger

Sub TestCopyFormat()

Dim Cell As Range
Dim Cindex As Integer
On Error GoTo errorhandler
Application.DisplayAlerts = False
With Worksheets("Sheet1")
For Each Cell In Range("E2:E100")
Cindex = WorksheetFunction.Match(Cell.Text, .Range("A2:A100"), 0)
.Range("B2:B100").Cells(Cindex, 1).Copy _
Destination:=Range("C2:C100").Cells(Cindex, 1)
Next Cell
End With
errorhandler:
Application.DisplayAlerts = True
End Sub


--

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
quick question Fady Excel Discussion (Misc queries) 7 February 23rd 08 04:59 AM
A quick way to edit the formula in check boxes Plum Excel Discussion (Misc queries) 1 August 8th 07 01:10 PM
Quick question about "filtering" macro johannes Excel Discussion (Misc queries) 2 January 1st 07 02:53 PM
Quick Macro question - How to delete two rows then skip one - and repeat David Smithz Excel Discussion (Misc queries) 3 March 3rd 06 02:58 PM
Quick Question Nikki Excel Worksheet Functions 4 January 31st 06 02:51 PM


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