?
Solved

Excel VBA for filling adjacent cells

Posted on 2013-05-15
3
Medium Priority
?
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 81

Accepted Solution

by:
byundt earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

764 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