Resize Range & Fill Column with Formula - Help

W

Walter

Here is the code I have but am having problems with my loop for filling the
cells in the new range:

Sub AutoFillColE()
'
' AutoFillColE Macro
' Auto fill col E based upon length of Current Region
'
Dim rngCell As Range
Dim rngCurrent As Range
Dim shtFlagelNoB05 As Worksheet

Set shtFlagelNoB05 = Application.ActiveWorkbook.Worksheets("Flagel_ERP_NoB05")
Set rngCurrent = shtFlagelNoB05.Range("A4").CurrentRegion
Set rngCurrent = rngCurrent.Offset(rowoffset:=1, columnoffset:=4)
Set rngCurrent = rngCurrent.Resize(RowSize:=rngCurrent, ColumnSize:=1)

'Paste formula in each cell in Column E from E5 down to bottom of new
range
For Each rngCell In rngCurrent
rngcell.Formula = "=IF(B4 <= TODAY()-77,"11+ Weeks",IF(B4 <=
TODAY()-42,"6 to 10 Weeks",IF(B4 <= TODAY()-7,"1 to 5 Weeks",IF(B4 >
TODAY()-7,"Current Week"))))"
Next rngCell

End Sub
 
W

Walter

For some reason my VBA editor does not like the formula line. It stays red:

rngcell.Formula = "=IF(B4 <= TODAY()-77,"11+ Weeks",IF(B4 <=TODAY()-42, _
"6 to 10 Weeks",IF(B4 <= TODAY()-7,"1 to 5 Weeks",IF(B4 >TODAY()-7, _
"Current Week"))))"
 
J

jknkboaters

In the IF statement the "11+ Weeks" needs to be entered ""11+ Weeks"" etc.

Two ways to enter code

One - break code into pieces with: " & _

rngcell.Formula.Formula = "=IF(B4<= TODAY()-77,""11+ Weeks""," & _
"IF(B4<=TODAY()-42,""6 to 10 Weeks""," & _
"IF(B4<=TODAY()-7,""1 to 5 Weeks""," & _
"IF(B4>TODAY()-7,""Current Week""))))"

Two - enter the code all together on one line of code (messy for printout)
(it wraps in the email but enter the entire code on one line in VB)

rngcell.Formula.Formula = "=IF(B4<= TODAY()-77,""11+
Weeks"",IF(B4<=TODAY()-42,""6 to 10 Weeks"",IF(B4<=TODAY()-7,""1 to 5
Weeks"",IF(B4>TODAY()-7,""Current Week""))))"

Jim K
 
J

jknkboaters

Correction - rngcell.Formula.Formula in first post should be rngcell.Formula

One - break code into pieces with: " & _

rngcell.Formula = "=IF(B4<= TODAY()-77,""11+ Weeks""," & _
"IF(B4<=TODAY()-42,""6 to 10 Weeks""," & _
"IF(B4<=TODAY()-7,""1 to 5 Weeks""," & _
"IF(B4>TODAY()-7,""Current Week""))))"

Two - enter the code all together on one line of code (messy for printout)
(it wraps in the email but enter the entire code on one line in VB)

rngcell.Formula = "=IF(B4<= TODAY()-77,""11+
Weeks"",IF(B4<=TODAY()-42,""6 to 10 Weeks"",IF(B4<=TODAY()-7,""1 to 5
Weeks"",IF(B4>TODAY()-7,""Current Week""))))"

Jim K
 

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