ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy of coloring format, now in diferent files (change of earlierrecieved code) (https://www.excelbanter.com/excel-programming/452687-copy-coloring-format-now-diferent-files-change-earlierrecieved-code.html)

[email protected]

Copy of coloring format, now in diferent files (change of earlierrecieved code)
 
Hello :)
Earlier received solutions works well, Thanks for it (see code below).
But I'm struckling now to change the code because the data is not longer in the same file as it was earlier.

Now it is:
wrkb1 should be the ActiveWorkbook.
wsh1 is always the sheetname "Data" in wrkb1.

wrkb2 is an open workbook with always the name "ColorData.xlsm"
wsh2 is always the sheetname "ColorFields" in wrkb2.
Info: In this workbook/sheet are the colored fields that has to be copieed to the records in wrkb1/wsh1.

Below code refered now only to two sheets in the same file.
Can somebody help me out to include in this code the reference to the other workbook.

regards,
Johan.
-----------------------------------------------------------------------------

Sub CopyFormat()
Dim wsh1 As Worksheet, wsh2 As Worksheet
Dim var1 As Variant, var2 As Variant
Dim i As Long, j As Long

Set wsh1 = Sheets("Sheet1")
Set wsh2 = Sheets("Sheet2")

Application.ScreenUpdating = False

var1 = wsh1.UsedRange
var2 = wsh2.UsedRange

For i = 2 To UBound(var1)
For j = LBound(var2) To UBound(var2)
If var1(i, 9) & var1(i, 10) = var2(j, 9) & var2(j, 10) Then
With wsh2
.Range(.Cells(j, "L"), .Cells(j, "UV")).Copy
wsh1.Cells(i, "L").PasteSpecial xlPasteFormats
End With
Exit For
End If
Next
Next
Application.ScreenUpdating = True
End Sub


All times are GMT +1. The time now is 08:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com