Hi all
I am trying to improve my skills with excel/VBA as I need it for my job. I started the course Excel/VBA for Creative Problem Solving, Part 1 in coursera and I am on module 2.
As far as I can see, my macro is correct. It works for me in my PC, but for some reason its failing in part C. Please, could you help me find what I am doing wrong?
x100000 thanks.
The exercise says the following
INSTRUCTIONS:
a) Create a subroutine called AddNumbersA that adds a number input into an input box to the value in cell D4. The result should be output in cell G12.
b) Create a subroutine called AddNumbersB that asks the user for a number, adds that number to the value in the active cell, then places the result in a cell that is 3 rows up and two columns right of the active cell. (Make sure that you select an appropriate active cell prior to running the sub!)
c) Create a subroutine called WherePutMe that asks the user for a row number and column letter then places the 2,2 position of a selection into that cell. (HINT: Make sure that you select a selection before running the sub!)
HINT: If x is an integer and is equal to 7 and y is a string and equal to "B", you can place z into cell B7 by: Range(y & x) = z. Hope this helps.
1. Start with a selection:
2. Run your WherePutMe subroutine, which asks the user for the row and column of the cell in which theyd like to place the result:
3. Your subroutine will take the 2,2 position of the initial selection (-4 in our example) and place it in cell C7 (specified by user in the two input boxes):
d) Create a subroutine called Swap that will swap the values in two adjacent cells (in the same row, anywhere on the spreadsheet). (Make sure that you select two adjacent cells before executing the sub!).
And my code is this
Option Explicit
Sub AddNumbersA()
'Place your code here
Dim x As Double, y As Double, z As Double
x = InputBox("Please, enter a Number:")
y = Range("D4")
z = x + y
Range("G12") = z
End Sub
Sub AddNumbersB()
'Place your code here
Dim x As Double, y As Double, z As Double
x = InputBox("Please, enter a Number:")
y = ActiveCell
z = x + y
ActiveCell.Offset(-3, 2) = z
End Sub
Sub WherePutMe()
'Place your code here
Dim x As Integer, y As String, z As String, n As Integer
x = InputBox("Please, enter a Number:")
y = InputBox("Please, enter a Letter:")
z = y & x
Selection.Range(z).Select
n = Selection
Range(z).Offset(2, 2) = n
End Sub
Sub Swap()
'Place your code here
Dim temp As Integer, b As Integer
temp = Selection.Cells(1, 1)
b = Selection.Cells(1, 2)
Selection.Cells(1, 2) = temp
Selection.Cells(1, 1) = b
End Sub
Can you guys please help me? I have also attached the file.
Thanks a lot
Bookmarks