Solved

Excel VBA for filling adjacent cells

Posted on 2013-05-15
3
283 Views
Last Modified: 2013-05-17
I need some code to fill adjacent cells with values from a preceding cells.  However, if the cell contains a value alread, I need it to skip the cell.


I woud like the values form the adjacent (column) cells updated by the one from the preceding cell.  However, if there is a value in the cells to be updated, I want to use it as the new value and fill in the remaining adjacent cells.
excel.JPG
0
Comment
Question by:Fairfield
3 Comments
 
LVL 1

Expert Comment

by:chrisezard
ID: 39169263
Do you need this to be automated by VBA?
If you just need to make a few infills, then...
Highlight the value you want to copy and the empty cells to the right of it that you want to fill, and press Ctrl+R. The empty cells will have the same value as the first cell you selected.
0
 

Author Comment

by:Fairfield
ID: 39169537
I would like this to be automated with VBA as there are over 38k rows of data.
0
 
LVL 80

Accepted Solution

by:
byundt earned 500 total points
ID: 39169954
Here is a macro to fill values to the right. As written, it works with the used range, starting with column B.
Sub FillRight()
Dim rg As Range, rgg As Range
With ActiveSheet
    Set rg = Selection.Cells
    If rg.Cells.Count = 1 Then Set rg = .UsedRange
    Set rgg = Range(.Cells(1, 2), .Cells(.Rows.Count, .Columns.Count))
    Set rg = Intersect(rg, .UsedRange)
    Set rg = Intersect(rg, rgg)
End With
On Error Resume Next
Set rg = rg.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If Not rg Is Nothing Then
    rg.FormulaR1C1 = "=RC[-1]"
End If
End Sub

Open in new window

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now