I need a line of code add to VB please help

muzzy

Active Member
Joined
Apr 8, 2014
Messages
333
I am trying to copy number down column A:A but when I see the word subtotal in column b:b do not copy in the A:A cell next to it but still copy down. This is the code I am trying to use. There was 3 codes on this page they will all work I just need that line of code add here is the link

http://www.contextures.com/xlDataEntry02.html#FillProg

Code:
Sub FillColBlanks_Offset() 'by Rick Rothstein  2009-10-24 'fill blank cells in column with value above 'http://www.contextures.com/xlDataEntry02.html    Dim Area As Range, LastRow As Long   On Error Resume Next   LastRow = Cells.Find(What:="*", SearchOrder:=xlRows, _                SearchDirection:=xlPrevious, _                LookIn:=xlFormulas).Row   For Each Area In ActiveCell.EntireColumn(1).Resize(LastRow). _                SpecialCells(xlCellTypeBlanks).Areas     Area.Value = Area(1).Offset(-1).Value   Next End Sub</pre>
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I took what you had copied and added an if statement. See if this does what you need.

Code:
Sub FillColBlanks_Offset()


'by Rick Rothstein  2009-10-24
'fill blank cells in column with value above
'http://www.contextures.com/xlDataEntry02.html
Dim Area As Range, LastRow As Long
On Error Resume Next
LastRow = Cells.Find(What:="*", SearchOrder:=xlRows, _
        SearchDirection:=xlPrevious, _
        LookIn:=xlFormulas).Row
For Each Area In ActiveCell.EntireColumn(1).Resize(LastRow).SpecialCells(xlCellTypeBlanks).Areas
    If (Area(1).Offset(0, 1).Value <> "subtotal") Then
        Area.Value = Area(1).Offset(-1).Value
    End If
Next
End Sub
 
Upvote 0
No it did not work

This is what I have
Assigned Role
Assigned
1-2-8-26-1-1-11ARTHUR
CHARLOTTE
GISELLE
LAVONE
Subtotal
1-2-8-26-1-2-13MARSHALL
MATTHEW
PASCAL
RACQUEL
Subtotal
1-2-8-26-1-1-12ABRIL
BRIA
DIANNA
Subtotal
1-2-8-26-2-2-12JERMELL
KIMBERLY
KRYSTENA
NATACHA
NIA
SHAMEKA
TAIQUIA
Subtotal

<colgroup><col><col></colgroup><tbody>
</tbody>

This is what I need or looking for?

Assigned Role
Assigned
1-2-8-26-1-1-11ARTHUR
1-2-8-26-1-1-11CHARLOTTE
1-2-8-26-1-1-11GISELLE
1-2-8-26-1-1-11LAVONE
Subtotal
1-2-8-26-1-2-13MARSHALL
1-2-8-26-1-2-13MATTHEW
1-2-8-26-1-2-13PASCAL
1-2-8-26-1-2-13RACQUEL
Subtotal
1-2-8-26-1-1-12ABRIL
1-2-8-26-1-1-12BRIA
1-2-8-26-1-1-12DIANNA
Subtotal
1-2-8-26-2-2-12JERMELL
1-2-8-26-2-2-12KIMBERLY
1-2-8-26-2-2-12KRYSTENA
1-2-8-26-2-2-12NATACHA
1-2-8-26-2-2-12NIA
1-2-8-26-2-2-12SHAMEKA
1-2-8-26-2-2-12TAIQUIA
Subtotal

<colgroup><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Code:
Sub lineOfCode()
    For x = 3 To Cells(Rows.Count, "B").End(xlUp).Row
        If UCase(Cells(x, 2)) <> "SUBTOTAL" And Cells(x, 1) = "" Then
            Cells(x, 1).Value = Cells(x - 1, 1).Value
        End If
    Next
End Sub
 
Upvote 0
Give this macro a try...
Code:
Sub FillInAssignedRoles()
  Dim LastRow As Long, Ar As Range
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  On Error Resume Next
  For Each Ar In Range("A1:A" & LastRow).SpecialCells(xlBlanks).Areas
    Ar.Resize(Ar.Rows.Count - 1).FormulaR1C1 = "=R[-1]C"
    Ar.Value = Ar.Value
  Next
  On Error GoTo 0
End Sub
 
Upvote 0
try changing subtotal to Subtotal in the IF statement. The code has a lower case S and the actual value has an upper case S
 
Upvote 0
try changing subtotal to Subtotal in the IF statement. The code has a lower case S and the actual value has an upper case S
You should either "Reply with quote" (reducing the text to the relevant sections) or mention whose post you are directing your comment to. Given that you didn't, I would like to point out that the code I posted does not need a fix for the word "subtotal" as my code does not directly check for that word.
 
Upvote 0
You should either "Reply with quote" (reducing the text to the relevant sections) or mention whose post you are directing your comment to. Given that you didn't, I would like to point out that the code I posted does not need a fix for the word "subtotal" as my code does not directly check for that word.
Sorry when I started my reply there were just 2 of us in the thread. 2 other posts joined while I was typing.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,938
Latest member
Aaliya13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top