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?
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks