I have located here at mrexcel.com a macro to multiply values in two adjacent columns A, B, and provide the result in column C - it works fine, however only at Sheet1 of workbook "personal.xlsm". Tried but was unsuccessful to make it work at any workbook. Shall much appreciate help to make this macro functional at any workbook. Thanks!
VBA Code:
Sub MultiplyColumns()
Dim ws As Worksheet
Dim rng As Range
Dim i As Long
' Set the worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
' Set the range to loop through (column A in this case)
Set rng = ws.Range("A1:A" & ws.Cells(ws.Rows.Count, "A").End(xlUp).Row)
' Loop through each cell in the range
For i = 1 To rng.Count
' Multiply column A and B values and put the result in column C
ws.Cells(i, "C").Value = ws.Cells(i, "A").Value * ws.Cells(i, "B").Value
Next i
End Sub