calling macros from worksheet to another

G

Guest

I have created a macro in sheet1 and stored it in view code of sheet1.
Now I copy the contents to sheet1 and also the viewcode to sheet2, but it
does not work. Can anyone help me in this matter.

Also How can I access or refer data/cells from one worksheet/Excel file in
other worksheet/Excel file while creating macros.
NSNR
 
G

Guest

PL FIND THE CODE AS FOLLOWS:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim jjj6, jj6, jj8 As Range
Dim dp As Integer

Set jjj6 = Cells(10, 6)
Set jjj7 = Cells(10, 7)
Set jjj8 = Cells(11, 3)

'Lengthtobeinput = InputBox("Enter Length", "Input", 1)
'Breadthtobeinput = InputBox("Enter Breadth", "Input", 1)
'Heighttobeinput = InputBox("Enter Height", "Input", 1)

'Cells(5, 3) = Lengthtobeinput
'Cells(7, 3) = Breadthtobeinput
'Cells(9, 3) = Heighttobeinput

'Cells(7, 5) = (Lengthtobeinput * Breadthtobeinput * Heighttobeinput) /
(1000000000)
Cells(7, 5) = (Cells(5, 3) * Cells(7, 3) * Cells(9, 3)) / (1000000000)


'ActiveCell.Offset(5, 4).Select
dp = Cells(7, 3).Value

If Cells(7, 3).Value = Cells(24, 3).Value Then
Cells(7, 7) = Cells(7, 5).Value * Cells(24, 5).Value
Cells(7, 8) = Cells(7, 5).Value * Cells(24, 7).Value

Cells(7, 10) = Cells(7, 5).Value * Cells(24, 9).Value
Cells(7, 11) = Cells(7, 5).Value * Cells(24, 11).Value

Else
If Cells(7, 3).Value = Cells(26, 3).Value Then
Cells(7, 7) = Cells(7, 5).Value * Cells(26, 5).Value
Cells(7, 8) = Cells(7, 5).Value * Cells(26, 7).Value

Cells(7, 10) = Cells(7, 5).Value * Cells(26, 9).Value
Cells(7, 11) = Cells(7, 5).Value * Cells(26, 11).Value
Else
If Cells(7, 3).Value = Cells(28, 3).Value Then
Cells(7, 7) = Cells(7, 5).Value * Cells(28, 5).Value
Cells(7, 8) = Cells(7, 5).Value * Cells(28, 7).Value

Cells(7, 10) = Cells(7, 5).Value * Cells(28, 9).Value
Cells(7, 11) = Cells(7, 5).Value * Cells(28, 11).Value
Else
If Cells(7, 3).Value = Cells(30, 3).Value Then
Cells(7, 7) = Cells(7, 5).Value * Cells(28, 5).Value
Cells(7, 8) = Cells(7, 5).Value * Cells(28, 7).Value

Cells(7, 10) = Cells(7, 5).Value * Cells(28, 9).Value
Cells(7, 11) = Cells(7, 5).Value * Cells(28, 11).Value
Else
If Cells(7, 3).Value = Cells(32, 3).Value Then
Cells(7, 7) = Cells(7, 5).Value * Cells(32, 5).Value
Cells(7, 8) = Cells(7, 5).Value * Cells(32, 7).Value

Cells(7, 10) = Cells(7, 5).Value * Cells(32, 9).Value
Cells(7, 11) = Cells(7, 5).Value * Cells(32, 11).Value
Else
If Cells(7, 3).Value = Cells(34, 3).Value Then
Cells(7, 7) = Cells(7, 5).Value * Cells(34,
5).Value
Cells(7, 8) = Cells(7, 5).Value * Cells(34,
7).Value

Cells(7, 10) = Cells(7, 5).Value * Cells(34,
9).Value
Cells(7, 11) = Cells(7, 5).Value * Cells(34,
11).Value
Else
If Cells(7, 3).Value = Cells(36, 3).Value Then
Cells(7, 7) = Cells(7, 5).Value * Cells(36,
5).Value
Cells(7, 8) = Cells(7, 5).Value * Cells(36,
7).Value

Cells(7, 10) = Cells(7, 5).Value * Cells(36,
9).Value
Cells(7, 11) = Cells(7, 5).Value * Cells(36,
11).Value
Else
If Cells(7, 3).Value = Cells(38, 3).Value Then
Cells(7, 7) = Cells(7, 5).Value *
Cells(38, 5).Value
Cells(7, 8) = Cells(7, 5).Value *
Cells(38, 7).Value

Cells(7, 10) = Cells(7, 5).Value *
Cells(38, 9).Value
Cells(7, 11) = Cells(7, 5).Value *
Cells(38, 11).Value
Else
If Cells(7, 3).Value = Cells(40,
3).Value Then
Cells(7, 7) = Cells(7, 5).Value *
Cells(40, 5).Value
Cells(7, 8) = Cells(7, 5).Value *
Cells(40, 7).Value

Cells(7, 10) = Cells(7, 5).Value *
Cells(40, 9).Value
Cells(7, 11) = Cells(7, 5).Value *
Cells(40, 11).Value
Else

End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
 
D

Dave Peterson

Is there a reason that you have this kind of code under the _selectionchange
event.

This means that each time you select a different range, the code will fire and
try to do stuff.

I think I'd remove the code from each worksheet module and put a single copy in
a General module.

Then you can use:

if activesheet.cells(x, y).value = worksheets("sheet2").cells(z,w).value then

to refer to different sheets (if the activesheet is not Sheet2).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top