so i tried asking chatbot this question and im not sure if this is right.....
In excel How do I use VBA to copy cells "C3" in sheet 1 to cell "E23" in sheet 2, cell "E3" in sheet 1 to cell "F5" in sheet 2, cell "G3" in sheet 1 to cell "B22" in sheet 2, cell "H3" in sheet 1 to cell "B13"in sheet 2, cell "I3" in sheet 1 to cell "B20" in sheet 2, cell "K3" in sheet 1 to cell "C20" in sheet 2 starting from row 3 from sheet 1 only if cell "E3" in sheet 1 is filled in and if column "K" in sheet 1 is filled in afterwards.
this is the code i got
Code
Sub CopyCells()
'Declare variables
Dim ws1 As Worksheet
Dim ws2 As Worksheet
'Set worksheets
Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")
'Check if cell E3 in Sheet1 is filled in
If ws1.Range("E3").Value <> "" Then
'Copy cell C3 from Sheet1 to cell E23 in Sheet2
ws2.Range("E23").Value = ws1.Range("C3").Value
'Copy cell E3 from Sheet1 to cell F5 in Sheet2
ws2.Range("F5").Value = ws1.Range("E3").Value
'Copy cell G3 from Sheet1 to cell B22 in Sheet2
ws2.Range("B22").Value = ws1.Range("G3").Value
'Copy cell H3 from Sheet1 to cell B13 in Sheet2
ws2.Range("B13").Value = ws1.Range("H3").Value
'Copy cell I3 from Sheet1 to cell B20 in Sheet2
ws2.Range("B20").Value = ws1.Range("I3").Value
'Check if cell K3 in Sheet1 is filled in
If ws1.Range("K3").Value <> "" Then
'Copy cell K3 from Sheet1 to cell C20 in Sheet2
ws2.Range("C20").Value = ws1.Range("K3").Value
End If
End If
End Sub
Display More