Excel macros how to autofill cells?

0

Hi i am not familiar with VBA code but i know java. I am looking to create a macro that checks if a cell is not blank and autofill the cells in another column but in the same row with the formula above them. Any ideas??

    975   805040   2065bc210    325647998522
    976   802030   2089bc212    325647956721
    977                        *325647964751*
    978                        *325647967866*
    979                        *325647964452*

Sorry for the lack of details. This is an example of my excel the left are the numbers of rows i need to autofill the other collumns when i add manually the numbers in stars. The other columns get their information from a formula. I cann't post a pic because my reputation is low.

Something like that but didn't worked

Sub CheckCell()
    Dim i As Integer
       i = 3

     Do
      Selection.AutoFill Destination:=Range("Ai:A(i+1)"), Type:=xlFillDefault  
     i = i+1
    Loop While (ActiveSheet.Range("Bi").Value != "")
 End Sub

rexxar

Posted 2013-03-20T13:35:05.600

Reputation: 45

i did that but the check is not recorded because i do it visual.I want the macro to autofill the other columns like i do with draging-aytofill until the last row of the cells that i added – rexxar – 2013-03-20T14:02:55.940

Please [edit] your question with more details about how the data is laid out and what the "autofill" source data is. What does "in the same row with the formula above them" mean? You say VBA and formula in the same question. Which do you want to use? – CharlieRB – 2013-03-20T14:33:02.057

Answers

1

This can be done in a couple ways;
(These examples assume cell to check is A2 and the autofill text is to go into B2. Adjust accordingly)

With a formula (placed in the cell you want the autofill text)

=IF(ISBLANK(A2),"autofill text","")

With VBA

Sub CheckCell()

    If ActiveSheet.Range("A2").Value = "" Then
        ActiveSheet.Range("B2").Value = "Autofill"
    End If

End Sub

NOTE: These examples are very basic and vague because you did not provide a lot of details in your question.

CharlieRB

Posted 2013-03-20T13:35:05.600

Reputation: 21 303

edited my question please check again – rexxar – 2013-03-21T08:54:41.633

0

After better searching the internet and testing i found this code worked.

Sub FillCells()

Dim i As Long
Dim k As Long
    With ActiveSheet
    k = .Cells(.Rows.Count, "K").End(xlUp).Row
    i = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
Range("a" & i & ":a" & k).Formula = Range("A" & i).Formula
Range("B" & i & ":B" & k).Formula = Range("B" & i).Formula
Range("C" & i & ":C" & k).Formula = Range("C" & i).Formula
Range("D" & i & ":D" & k).Formula = Range("D" & i).Formula
Range("E" & i & ":E" & k).Formula = Range("E" & i).Formula
Range("F" & i & ":F" & k).Formula = Range("F" & i).Formula
Range("G" & i & ":G" & k).Formula = Range("G" & i).Formula
Range("H" & i & ":H" & k).Formula = Range("H" & i).Formula
Range("I" & i & ":I" & k).Formula = Range("I" & i).Formula
Range("J" & i & ":J" & k).Formula = Range("J" & i).Formula
Range("M" & i & ":M" & k).Formula = Range("M" & i).Formula
Range("N" & i & ":N" & k).Formula = Range("N" & i).Formula
Range("O" & i & ":O" & k).Formula = Range("O" & i).Formula
Range("P" & i & ":P" & k).Formula = Range("P" & i).Formula
Range("U" & i & ":U" & k).Formula = Range("U" & i).Formula
Range("Y" & i & ":Y" & k).Formula = Range("Y" & i).Formula
Range("Z" & i & ":Z" & k).Formula = Range("Z" & i).Formula

End Sub

rexxar

Posted 2013-03-20T13:35:05.600

Reputation: 45