Hello,
I am using the below Macro to copy Colomn "C" in sheet1 to Column "D" in sheet 2. I was wondering if it is possible instead of having predetermined copy and paste columns, that I can specify when the Macro is run. Meaning when I run the Macro, I get a dialog box that pops up that allows me to enter the sheet1 column for copy and once I enter that column, the next box pops up for me to enter the sheet2 destination column?
Thanks Jr
I am using the below Macro to copy Colomn "C" in sheet1 to Column "D" in sheet 2. I was wondering if it is possible instead of having predetermined copy and paste columns, that I can specify when the Macro is run. Meaning when I run the Macro, I get a dialog box that pops up that allows me to enter the sheet1 column for copy and once I enter that column, the next box pops up for me to enter the sheet2 destination column?
Code:
Option Explicit
Sub CtoD()
Dim wsOne As Worksheet, wsTwo As Worksheet
Dim arrOne, arrTwo, j As Long, jj As Long
Dim lrOne As Long, lrTwo As Long
Set wsOne = Worksheets("Sheet1")
Set wsTwo = Worksheets("Sheet2")
lrOne = wsOne.Cells(Rows.Count, "A").End(xlUp).Row
lrTwo = wsTwo.Cells(Rows.Count, "A").End(xlUp).Row
arrOne = wsOne.Range("A1:C" & lrOne).Value2
arrTwo = wsTwo.Range("A1:D" & lrTwo).Value2
For j = LBound(arrOne) To UBound(arrOne)
For jj = LBound(arrTwo) To UBound(arrTwo)
If arrTwo(jj, 1) = arrOne(j, 1) Then
arrTwo(jj, 4) = arrOne(j, 3)
End If
Next jj
Next j
wsTwo.Range("A1").Resize(UBound(arrTwo), 4).Value = arrTwo
End Sub
Thanks Jr