Help with inputbox cel reference

J

Janet H

The input box routine below does exactly what I want it to - but only on the
first line. I want to modify it so it works on every row. The cell references
of b, j & K remain the same but the line reference varies. How do I set it up
so it knows what line it's on?

I'm a newbie so some extra explanation is helpful. Thanks!

ActiveSheet.Unprotect
Range("b63").Select
ActiveCell = "x"
mynum = Application.InputBox("Payment including Adj")
Range("j63").Value = mynum
mynum = Application.InputBox("Enter total overpayment remaining")
Range("k63").Value = mynum
ActiveSheet.Protect
 
C

Cory

Janet,

Some clarification may be needed, namely what you mean by wanting the macro
to work on every row. I will assume that you want to be able to run the macro
on whatever line you are currently on. If this is the case, you won't need
the Range("B63").Select command.

To find out the current line (row) that the macro is on use the following:

ActiveCell.Row

You can also simplify your code by assigning the InputBox statements
directly to a cell value rather than first assigning it to a variable and
then assigning that variable to the cell. Putting all of this together you
end up with the following:

ActiveSheet.Unprotect
Range("B" & ActiveCell.Row) = "x"
Range("J" & ActiveCell.Row) = Application.InputBox("Payment including
Adj")
Range("K" & ActiveCell.Row) = Application.InputBox("Enter total
overpayment remaining")
ActiveSheet.Protect

Hope this helps.
-Cory
 
T

Tom Ogilvy

Dim cell as Range
ActiveSheet.Unprotect
for each cell in Range("B63:B50")
cell.Select
ActiveCell = "x"
mynum = Application.InputBox("Payment including Adj")
Cells(cell.row,"J").Value = mynum
mynum = Application.InputBox("Enter total overpayment remaining")
cells(cell.row,"k").Value = mynum
Next
ActiveSheet.Protect
 

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