Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA loop help

Status
Not open for further replies.

maxxev

Technical User
Jul 17, 2008
139
NL
Hi can you help me please to identify what is wrong with my code (it doesn't do anything)

Code:
Sub FillEveryOtherColumn()

    Dim lastCell As Integer
    Dim lastColumn As Integer
    Dim i As Integer

    Dim End1 As Integer
    Dim Start2 As Integer
    Dim End2 As Integer
    
    Application.ScreenUpdating = False

'Find last populated column after Column G
lastCell = Range("G1").End(xlToRight).Column
'Calculate the number of Columns you'll need to fill
lastColumn = (lastCell / 2) + 1

'Find last populated row in first half of column (58 rows before the end)
End1 = Cells(Rows.Count, "A").End(xlUp).Row - 58
'Find first populated row in 2nd half of column (41 rows before the end
Start2 = End1 - 41
'Find last populated row
End2 = Cells(Rows.Count, "A").End(xlUp).Row
'Start with Column G (Column 7), and fill every other column

For i = 7 To lastColumn Step 1
    Range(Cells(7, i), Cells(End1, i)).Select
        Selection.FillDown
    Range(Cells(Start2, i), Cells(End2, i)).Select
        Selection.FillDown
Next i
    Application.ScreenUpdating = True
End Sub
 



Hi,

Please post VBA code questions in forum707.

This forum focuses on MS Office applications' native features.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top