Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Sheet to sheet code Type Mismatch


I want to go down the list on sheet2 D column and compare to sheet1 A column and if a match copy column A .Offset(0, 1) back to sheet2 column D .Offset(0, 1).

I can't sniff out the type mismatch error I'm getting.

Then I need to do the same thing as this code but do it between two workbooks.

Thanks,
Howard

Option Explicit

Sub S_1ToS_2()
Dim c As Range
Dim c1 As Variant

For Each c In Sheets(Sheet2).Range("D1:D10")
For Each c1 In Sheets(Sheet1).Range("A1:A25")
If c1.Value = c.Value Then
c1.Offset(0, 1).Copy c.Offset(0, 1)
End If
Next
Next

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Sheet to sheet code Type Mismatch

Hi Howard,

Am Tue, 23 Apr 2013 02:47:32 -0700 (PDT) schrieb Howard:

I want to go down the list on sheet2 D column and compare to sheet1 A column and if a match copy column A .Offset(0, 1) back to sheet2 column D .Offset(0, 1).

I can't sniff out the type mismatch error I'm getting.

Then I need to do the same thing as this code but do it between two workbooks.


without looping through all cells in both sheets:

Sub Sh1_To_Sh2()
With Sheets("Sheet2").Range("E1:E10")
.Formula = "=Vlookup(D1,Sheet1!A1:B25,2,0)"
.Value = .Value
End With
End Sub


Regards
Claus Busch
--
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: 3,872
Default Sheet to sheet code Type Mismatch

Hi Howard,

Am Tue, 23 Apr 2013 12:00:10 +0200 schrieb Claus Busch:

.Formula = "=Vlookup(D1,Sheet1!A1:B25,2,0)"


there is a typo in the formula above.
Change to:
..Formula = "=Vlookup(D1,Sheet1!$A$1:$B$25,2,0)"


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Sheet to sheet code Type Mismatch

Am Tue, 23 Apr 2013 02:47:32 -0700 (PDT) schrieb Howard:

I can't sniff out the type mismatch error I'm getting.


you can refere to your sheet with sheet name or with code name

Either you have to write:
For Each c In Sheets("Sheet2").Range("D1:D10")
or:
For Each c In Sheet2.Range("D1:D10")


Regards
Claus Busch
--
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 Sheet to sheet code Type Mismatch

On Tuesday, April 23, 2013 3:17:10 AM UTC-7, Claus Busch wrote:
Am Tue, 23 Apr 2013 02:47:32 -0700 (PDT) schrieb Howard:



I can't sniff out the type mismatch error I'm getting.




you can refere to your sheet with sheet name or with code name



Either you have to write:

For Each c In Sheets("Sheet2").Range("D1:D10")

or:

For Each c In Sheet2.Range("D1:D10")





Regards

Claus Busch

Thanks Claus, works perfectly.

I may be back to get the proper syntax to do the same between two workbooks.
Seems I just need to get the workbook names in front of the sheet names and use the same bacic code.

Regards,
Howard



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Sheet to sheet code Type Mismatch


Thanks Claus, works perfectly.



I may be back to get the proper syntax to do the same between two workbooks.

Seems I just need to get the workbook names in front of the sheet names and use the same bacic code.



Regards,

Howard


Easier than I thought.

This seems to work just fine from workbook to workbook.

Sub Bk4_To_Bk3()
With Sheets("Sheet2").Range("I1:I10")
.Formula = "=VLOOKUP(H1,[Book4]Sheet1!$A$1:$B$25,2,0)"
.Value = .Value
End With
End Sub

Thanks much, Claus. Always appreciate your fine advice.

Regards,
Howard
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Sheet to sheet code Type Mismatch

Hi Howard,

Am Tue, 23 Apr 2013 04:38:45 -0700 (PDT) schrieb Howard:

Easier than I thought.

This seems to work just fine from workbook to workbook.

Sub Bk4_To_Bk3()
With Sheets("Sheet2").Range("I1:I10")
.Formula = "=VLOOKUP(H1,[Book4]Sheet1!$A$1:$B$25,2,0)"
.Value = .Value
End With
End Sub


always glad to help. Thank you for the feedback.
If you have spaces in the workbook name don't forget the apostrophes.


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
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
Help to DEBUG this line of code. Type mismatch error Ayo Excel Programming 9 October 20th 09 09:08 PM
Type Mismatch error in VBA code bobby Excel Programming 3 November 10th 05 08:05 AM
[Q] Save As throws type mismatch error in control's code? Jason Weiss Excel Discussion (Misc queries) 1 July 16th 05 04:21 AM
type mismatch in this code Jay Baxter Excel Programming 4 February 26th 04 06:36 PM
Code works 1st time then Type Mismatch when checking for not blank cells Colleyville Alan Excel Programming 3 February 6th 04 05:21 AM


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