Forum

How do i Automatica...
 
Notifications
Clear all

How do i Automatically Trigger the macros for Sheet 2 When Value Change Occur in One Sheet 1

2 Posts
2 Users
0 Reactions
57 Views
(@jackbhai)
Posts: 1
New Member
Topic starter
 

I have Sheet 1 and Sheet 

Sheet 1 => https://paste.pics/6d48d50d54592eb1bdcb31e727b44958

Sheet 2 => https://paste.pics/80f4230bf6819a80ed36e1b6415ece08

Value of Sheet 1 => F5 => '50'  => is referenced in Sheet 2  => E4 => '50'

 

When i enter Value in Sheet 1 in place of F5 => Value gets Change in Sheet 2 => E4 => Automatically

 

Now the issue is
I want to print the DATA 1 and DATA 2 of Sheet 2 => That many times => how much value which is shown in place of Sheet 2 => E4 [Position] => in place of COLUMN => 'I' and 'J'

 

Like this Below Output :

https://paste.pics/494c856d2908a83ca031ee20bb706a09

 

My code which partially which print only one Column output but need to PRINT 'RAM' and 'RAJ' => COLUMN => 'I' and 'J'

 

Module :

Sub mac()

Dim ws As Worksheet
Dim rDest As Range
Dim lCount As Long
Dim sValue As String

Set ws = ThisWorkbook.Sheets("Sheet2")
Set rDest = ws.Range("I2")

With ws.Range(rDest, ws.Cells(ws.Rows.Count, rDest.Column).End(xlUp))
If .Row >= rDest.Row Then .ClearContents
End With

lCount = Val(ws.Range("E4").Value)
sValue = ws.Range("E8").Value

If lCount > 0 Then rDest.Resize(lCount) = sValue

End Sub

 

Code for Sheet 1 : to enable call => of macros => mac

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Sheets("Sheet1").Range("F5"), Target) Is Nothing Then
Call mac
End If
End Sub

 

 

 

 
 

 
Posted : 27/05/2019 3:44 am
Philip Treacy
(@philipt)
Posts: 1631
Member Admin
 

Hi,

You don't need VBA to do this.  You can use a formula like this copied down as many rows as you need.

    =IF($E$4-(ROW(A2)-ROW($I$1)-1)>0,$E$8,"")

See attached workbook for examples.

Regards

Phil

 
Posted : 28/05/2019 8:02 pm
Share: