Solved

Excel VBA for filling adjacent cells

Posted on 2013-05-15
3
317 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 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

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

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.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

749 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