Link to home
Start Free TrialLog in
Avatar of varesources
varesourcesFlag for Afghanistan

asked on

Excel - Multiply two cells go to next row?

I have over a thousand rows in an excel sheet. Column w needs to multiply by column v and place the answer in column y. Repeat until there is no more data in v or w. I know this is going to be a simple answer but I can't seem to find it. Thanks!

Oh, and I need it in a macro.
Avatar of SiddharthRout
SiddharthRout
Flag of India image

I would suggest that you do this via a formula but if you want to do it via macro then check this out.

Sub Sample()
    Dim ws As Worksheet
    Dim LastRow As Long, lastRowW As Long, lastRowV As Long, i as Long
    Set ws = Sheets("Sheet1")
    
    Application.ScreenUpdating = False
    
    lastRowW = ws.Range("W" & Rows.Count).End(xlUp).Row
    lastRowV = ws.Range("V" & Rows.Count).End(xlUp).Row
    
    If lastRowW > lastRowV Or lastRowW = lastRowV Then
        LastRow = lastRowW
    Else
        LastRow = lastRowV
    End If
    
    For i = 1 To LastRow
        ws.Range("Y" & i).Value = ws.Range("W" & i).Value * ws.Range("V" & i).Value
    Next i
    
    Application.ScreenUpdating = True
    
    MsgBox "Done"
End Sub

Open in new window


Sid
Avatar of Saqib Husain
In cell W1 type

=v1*w1

and then press enter

select cell W1 again

There is a tiny square at the bottom right corner of the selected cell

drag this cell as far down as necessary

Saqib
SOLUTION
Avatar of dlmille
dlmille
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of varesources

ASKER

Sid,

I get an error that says Run-time error '13':
Type mismatch.

End   Debug  Help

This row is highlighted when I click debug
ws.Range("Y" & i).Value = ws.Range("W" & i).Value * ws.Range("V" & i).Value
Change

ws.Range("Y" & i).Value = ws.Range("W" & i).Value * ws.Range("V" & i).Value

To

ws.Range("Y" & i).Value = Val(ws.Range("W" & i).Value) * Val(ws.Range("V" & i).Value)

Sid
Try mine :)  a bit late, but tested with sample spreadsheet attached

Dave
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sid yours worked just fine.

Dave I'm in a hurry and didn't get a chance to try it buy I will award you some points for the effort. Thanks!