Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

macro to copy & fill cells 3

Status
Not open for further replies.

poli60

Chemical
Joined
May 3, 2012
Messages
115
Location
IT
Hi Experts.
Columns B and C of the attached file have "sparse data".
Would it be possible to fill - by a VBA macro - all the cells under a certain value with the same value?
For instance:
- B3, B4 -> TOYOTA (as B2)
- C9 - C15 -> MILANO (as C7)
Grateful for any help you can provide :-)
 
 http://files.engineering.com/getfile.aspx?folder=23d9ca65-cd20-45e7-96be-05070c8c3a76&file=STAT.xlsx
first attempt:
- select the area for copying (B2:C75)
- F5 / special / blanks / OK
- select B3
- +B2
- CTLR-ENTER
that's all!
now, I'll try to register the code
 
VBA code
______________________________
Sub copia_sotto()
'
'copia nelle celle vuote sottostanti il valore di una cella
'nb: selezionare in precedenza l'area di applicazione
'
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=+R[-1]C"
End Sub
______________________________

It seems good enough but improvements/suggestions are welcome
 
That's pretty neat.

I guess the only addition I can think of is you might like to select the whole column (from B3) and paste as values.

Doug Jenkins
Interactive Design Services
 
I like your solution! Have a StAr!

Here's my take on the next step. You start by selecting any and all HEADINGS in columns that you want to "fill in the blanks". Then run the procedure. It will put your formula in all blank cells, copies the column of data and pastes values...
Code:
Sub FillInBlanks()
'select the HEADINGS for the columns you want to fill in

    With Selection
        With Intersect(.EntireColumn, .CurrentRegion)
            .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
            
            .Copy
            .PasteSpecial xlPasteValues
        End With
    End With
End Sub

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Thank you Doug and Skip.
I'll follow your suggestions.
Kind regards,
poli
 
Skip's code didn't work for me, probably because I didn't read the comment, and selected the whole range rather than the headings.

But the code below will do the whole process in one step (assuming that all formulas in the selected range should be converted into text, so use with care):

Code:
Sub FillInBlanks()
'Select the range you want to fill in

Selection.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=+R[-1]C"
 
With Selection
    .Copy
    .PasteSpecial xlPasteValues
End With
End Sub

Doug Jenkins
Interactive Design Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top