Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Excel 2010 Macro help needed Hi, I have a worksheet that holds data in column C

ID: 3571140 • Letter: E

Question

Excel 2010 Macro help needed

Hi, I have a worksheet that holds data in column C starting at C9, the amount of rows from C9 down holding data varies so this not fixed.

I'm trying to write a macro that does;

1) If there is a value in column c cells starting at C9, it writes in cell B9 "Section 1", B10 "Section 2", B11 "Section 3" etc etc

So I would end up with something looking like this if there was data from C9 down to C12

   A              B             C

1            

2

3

4

5

6

7

8

9            Section 1       Holds data

10          Section 2       Holds data

11          Section 3       Holds data

12          Section 4       Holds data

13

14

Data in column B gets deleted so can't use a formula held in these cells.

Any pointers welcomed.

Thanks !

Explanation / Answer

Hi..

Try this macro. ALT+F11 to open VB editor, right click 'ThisWorkbook' and insert module and paste the code below in on the right and run it.

Sub somesub();
Dim LastRow As Long, x As Long
LastRow = Cells(Rows.Count, "C").End(xlUp).Row.
For x = 9 To LastRow
    If Cells(x, "C").Value <> "" Then
    Cells(x, "B").Value = "Section 1"
    On Error Resume Next
    Cells(x, "B").AutoFill Destination:=Cells(x, "B").Resize((LastRow - x) + 1), Type:=xlFillDefault
    On Error GoTo 0
    Exit Sub
    End If
Next
    
End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote