VBA FooD PowerPoint Presentation × ds/ME309ClassNotes20180125-1 pdf 62% 62 Exerc
ID: 3881046 • Letter: V
Question
VBA FooD PowerPoint Presentation × ds/ME309ClassNotes20180125-1 pdf 62% 62 Exercise: Sub Procedure Cell I/O and a Sub called by another Sub 1 Before Create a worksheet input/output area as shown on the right, and enter the values shown for a and b. 10 20 5 After Write a sub procedure named "CellSwapper" to do the following (in this order): Read the values of "a" and "b" from the "Before:"area in column B, storing the values in procedure variables Call another sub procedure named "Switch", passing the variables for "a" and "b" to it. Output the values of "a" and "b" to the "After:" area in column B. Write a sub procedure named "Switch" to do the following: Declare input variables for "a" and "b".Explanation / Answer
Hi,
I have modified your code and not it performs the swapping you need. VBA code-
Sub CellSwapper()
Dim a, b As Double
Worksheets("sheet1").Select
a = Range("b2")
b = Range("b3")
Call switch(a, b)
'a2=b
'b2=a
End Sub
Sub switch(ByVal a As Double, ByVal b As Double)
Dim a2 As Double
Dim b2 As Double
Worksheets("sheet1").Select
a2 = Range("b6")
b2 = Range("b7")
Range("b6") = b
Range("b7") = a
End Sub
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.