worksheet_selection change with formula

nidhipatel

New Member
Joined
Feb 11, 2017
Messages
42
when i enter a value in any cell of Range A2:A6 and B2:B6 then out put (multiplication of Range A2:A6 and B2:B6) will be shown in C2:C6
i do this only by worksheet selection change event by macro ex.

when i input value in "A2" and "B2" then out put show in "C2" or when i enter any value in "A3" and "B3" then output show in "C3". then respectively other cell.
 

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

gallen

Well-known Member
Joined
Jun 27, 2011
Messages
2,006
confused why you need to do it via a macro. Also confused as to what your actual issue is.
 

L. Howard

Well-known Member
Joined
Oct 16, 2012
Messages
4,514
Try this in the sheet module.

Howard

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A2:B6")) Is Nothing Then Exit Sub

Dim OneRng As Range

Set OneRng = Range(Cells(2, 3), Cells(6, 3))

    With OneRng
      .Formula = "=A2*B2"
      .Value = .Value
    End With

End Sub
 

nidhipatel

New Member
Joined
Feb 11, 2017
Messages
42
problem is when i enter value in A2 and B2 then output shown only in C2 or when i enter value A3 and B3 then output show in C3 only other wise nothing not "zero"
 

nidhipatel

New Member
Joined
Feb 11, 2017
Messages
42
i create a invoice when i enter value in "qty" heading like "A2" and heading "Rate" like "B2" then output show only heading "Total" like "C2" condition is when i enter data in rang then show output. understand
 

L. Howard

Well-known Member
Joined
Oct 16, 2012
Messages
4,514
Maybe this?

Howard

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A2:B6")) Is Nothing Then Exit Sub

Dim OneRng As Range

Set OneRng = Range(Cells(2, 3), Cells(6, 3))

    With OneRng
      .Formula = "=IFERROR(IF(A2*B2=0,"""",A2*B2),"""")"
      .Value = .Value
    End With
    
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,119,302
Messages
5,577,277
Members
412,779
Latest member
Kings11Q
Top