0

I have fRange stored as range. Now I want fRange to go 1 down and 1 to the right. From here input boxes need to pop-up. Every time an input box is filled in it needs to move to the right until the cell has an other color.

The problem that I have is that everything I put in the input box, comes in the wrong cell. Have this now, so think there is something wrong with the offset

i = 3
u = 1
fRange = fRange.Offset(1, u)

Do While Cells(1, i).Interior.Color = RGB(69, 105, 142)


fRange = InputBox("Add price", Cells(1, i))


i = i + 1
u = u + 1


Loop

1 Answer 1

1

Please see VBA Best Practices documentation


You're missing the Set keyword. If you used Option Explicit at the top of your modules and declared your variables you wouldn't have this problem.

fRange is a Range object. Objects have to be Set in VBA.

i = 3
u = 1
Set fRange = fRange.Offset(1, u)

Do While Cells(1, i).Interior.Color = RGB(69, 105, 142)


fRange = InputBox("Add price", Cells(1, i))


i = i + 1
u = u + 1


Loop
5
  • 1
    fRange = InputBox("Add price", Cells(1, i)) was probably correct - implicitly using fRange.Value. (But I think the Set fRange is probably meant to be within the Do.)
    – YowE3K
    Commented May 28, 2017 at 19:54
  • @YowE3K aha yes that would make more sense, I'll edit my example Commented May 28, 2017 at 19:59
  • But maybe it is Set fRange = fRange.Offset(1, 0) inside the Do? (I think the OP should rewrite it to just use one variable - either i or u - not both.)
    – YowE3K
    Commented May 28, 2017 at 19:59
  • @YowE3K The logic is definitely wrong, u is never used and the loop looks at Cells instead of fRange - also as you've pointed out fRange isn't set to a new range at any point. I feel like correcting all that is just handing it on a plate to the OP instead of encouraging them to learn best practice first though. Commented May 28, 2017 at 20:02
  • I suspect that row 1 is a heading, and fRange is probably initially pointing to a row that is applicable to a date, and that the offset fRange is probably meant to just be referring to Cells(r, i) where r is that row number. But it is impossible to tell from the question, so the OP will have to work out that for themself.
    – YowE3K
    Commented May 28, 2017 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.