start macro with data in input box

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
821
Office Version
  1. 365
Platform
  1. Windows
hi
This works:
Code:
Sub startbox()
Dim i As Long
n = InputBox("                   Where Should the Fill Color Start?")
x = InputBox("                   How many times to run?")
Range("B" & n).Select
    For i = 1 To x
    With Range("A1:I1").Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 16645315
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Next i
End Sub
This doesn't. It only runs once.
Code:
Sub unfillnew()
Dim i As Long
n = InputBox("                   Where does the Un fill Start?")
x = InputBox("                   How many times to run?")
Range("B" & n).Select
    For i = 1 To x
   ActiveCell.Range("A1:I1").Select
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Next i
    ActiveCell.Select
End Sub
I can't see what I'm doing wrong :banghead:


The top one changes the fill of the row the user puts in the input box and does it x number of times
I'm trying to have a macro change the row back to "no fill" base on the user's input. start and x times.

Being a "still learning", I thought I could easily just change some of the working macro to suit the new conditions.
I had to add >>ActiveCell.Select << in the second to get the cursor back to the starting point (Range("B" & n).Select)
the first one didn't need it.
Also. If I want to combine the two can I just change the N and X of the second one?????

mike
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
:confused:
You're first code will put the fill on range A1:I1, regardless of what the user puts in the 2 input boxes.
 
Upvote 0
Hi Fluff
When I run this (some of this I got with help here. some with google)
Code:
Sub startbox()
Dim i As Long
n = InputBox("                   Where Should the Fill Color Start?")
x = InputBox("                   How many times to run?")
Range("B" & n).Select
    For i = 1 To x
    With Range("A1:I1").Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 16645315
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Next i
End Sub
I put in a number in the first box to where I want the fill to start, then the second box tells how many times to run it
I've used different combination of numbers and it works fine (so Far)


I thought I could just change the >>with range>> and the words of the input boxes.
The first part works >>where to start, but it only runs once no matter what was put in the second box

The sheet has every other row filled with an interior color from B to I
When I sort, the fill doesn't go with the data.
The first macro (startbox) corrects that
Sometimes I have to manually >>fil..no color>> some rows because of where the sort ended up. I am trying to make a macro for that.
I tried to put in a fixed starting point and range, but I would have to change that as data is added.

mike
 
Upvote 0
In that case there is something else going on, because you have hardcoded this range
Code:
 With Range("A1:I1").Interior
so they should be the only cellls getting filled
 
Upvote 0
boy am I stupid and embarrassed

I was using a macro to sort then it would call the startbox macro. I didn't realize I had 2 startbox macros and it would run this one. The one that I was trying to modify was the other one.
I guess I couldn't get the other to work and came up with this one. I have a habit of not deleting. And at my age, not remembering.
HTML:
Sub startbox()
Dim i As Long
n = InputBox("                Where Should the Fill Color Start?")
x = InputBox("                How many times to run?")
Range("B" & n).Select
    For i = 1 To x
        Call forfillingcolor
    Next i
End Sub
the macro >>forfillingcolor is
HTML:
Sub forfillingcolor1()
    ActiveCell.Range("A1:I1").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 16645315
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    ActiveCell.Offset(2, 0).Range("A1").Select
End Sub

I changed the input boxes and the call macro
the call macro only runs once not x times
Code:
Sub startbox2()
Dim i As Long
n = InputBox("                   Where Should the UnFill Color Start?")
x = InputBox("                   How many times to run?")
Range("B" & n).Select
    For i = 1 To x
       Call unfil
    Next i
End Sub
and
Code:
Sub unfil()
    ActiveCell.Range("A1:I1").Select
    With Selection.Interior
        .Pattern = alnone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    ActiveCell.Range("A1").Select
End Sub
I tried calling unfil using the top startbox macro and still it only runs once
I went thru all the macros for the sheet to make sure I didn't have any with the same name.

Thanks for your patients


mike
 
Upvote 0
yep I see my error it kept running the macro on the same line. DUH.

Thank you for your help.

And your patience

Mike
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top