+ Reply to Thread
Results 1 to 2 of 2

Thread: autofill column with VBA

  1. #1
    Registered User
    Join Date
    06-23-2011
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003
    Posts
    1

    autofill column with VBA

    My problem is that I am trying to create some VBA code that I can insert into a macro that will auto populate a new column with data that lies in the second row.

    For instance I have Data in column A that travels all the way down to row 124. I need to have a column next to it with "LAND_USE" in every row that contains data next to it. I can accomplish this with a macro recorder just fine. The problem is that the data I deal with is consistently changing the amount of rows to use. And if I change the range to 65536 then it will autofill all of the rows in excel which I do not want to happen, just the rows that contain data.

    Is there some VBA code that I can accomplish this task with that I can insert into another macro?

  2. #2
    Forum Guru Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007
    Posts
    3,521

    Re: autofill column with VBA

    Basic code, adapt as needed.
    Uses autofilter to show only cells in column-A that are not blank then fills visible cells in column-B with "Land_Use"

    Option Explicit
    
    Sub Fill_Cells()
    
        Dim lastrow As Long
        
        lastrow = Cells(Rows.Count, "A").End(xlUp).Row
        
        Application.ScreenUpdating = False
        
        With ActiveSheet
            .AutoFilterMode = False
            Range("A1:A" & lastrow).AutoFilter field:=1, Criteria1:="<>"
            .Range("A1:A" & lastrow - 1).Offset(1, 1).SpecialCells(xlCellTypeVisible).Cells.Value = "Land_Use"
            .AutoFilterMode = False
        End With
        
        Application.ScreenUpdating = True
    End Sub
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0