ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy format based on identical datafields (https://www.excelbanter.com/excel-programming/452415-copy-format-based-identical-datafields.html)

[email protected]

Copy format based on identical datafields
 
Hello,

Struckling in previously obtained help and codes (thanks!) I want to built it up on another way and in some steps, so I can understand it better (also to learn a bit).

The macro somebody can hopely create for me;

--------

When push the button start a macro.
Sheet1:
Run a loop from row2 till last.
For each record:
Select the combined tekst in "Column_I + Column_J".
Sheet2:
Search in sheet2 to the indentical combined text in "Column_I + Column_J".
If found:
copy the format of that row in sheet2 from "Column_L till Column_UV"
to the active record in sheet1 to "Column_L till Column_UV".
If not found:
Next row till last one.

regards,
Johan


Claus Busch

Copy format based on identical datafields
 
Hi Johan,

Am Tue, 11 Oct 2016 11:06:44 -0700 (PDT) schrieb :

When push the button start a macro.
Sheet1:
Run a loop from row2 till last.
For each record:
Select the combined tekst in "Column_I + Column_J".
Sheet2:
Search in sheet2 to the indentical combined text in "Column_I + Column_J".
If found:
copy the format of that row in sheet2 from "Column_L till Column_UV"
to the active record in sheet1 to "Column_L till Column_UV".
If not found:
Next row till last one.


try:

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


Regards
Claus B.
--
Windows10
Office 2016

[email protected]

Copy format based on identical datafields
 
Works. Some parts minor rebuilded.
Thanks!

regards,
Johan


All times are GMT +1. The time now is 04:54 AM.

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