+ Reply to Thread
Results 1 to 7 of 7

Macro fill the text in the specific column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-29-2011
    Location
    South Korea
    MS-Off Ver
    Excel 2019
    Posts
    178

    Macro fill the text in the specific column

    Dear all,

    I would like to write macro to fill in the blank columns (column B,C, D and E) or (Column B,C and E is also OK). I tried to search in the forum, most of them only can fill in the one column or for column A. I use the google search, there is a macro, however, it only applied on one forum. May I ask how to modify it, therefore, I can fill the text in the more than one columns? [for example B1 has the text , B2 doesn't have text]


    Thanks for your help. Sorry that I tried to made the macro format in the thread more proper, it still not success.......
    Sorry that I forget the source of macro:
    http://www.contextures.com/xlDataEntry02.html

    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
    Last edited by ronlau123; 05-23-2011 at 10:35 AM. Reason: Added Code Tags

  2. #2
    Forum Contributor
    Join Date
    04-29-2011
    Location
    South Korea
    MS-Off Ver
    Excel 2019
    Posts
    178

    Smile Re: Macro fill in the blank column

    Quote Originally Posted by ronlau123 View Post
    Dear all,

    I would like to write macro to fill in the blank columns (column B,C, D and E) or (Column B,C and E is also OK). I tried to search in the forum, most of them only can fill in the one column or for column A. I use the google search, there is a macro, however, it only applied on one forum. May I ask how to modify it, therefore, I can fill in the blank more than one columns? It is much better, if I can choose/edit which column fill in the blank column in the macro (e.g. it is easy to change column Bcde to efgh).

    Thanks for your help. Sorry that I tried to made the macro format in the thread more proper, it still not success.......

    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

    Dear Leith Ross,

    Thanks for helping to me add the "tag". May I know how can I add/change the format of macro more properly.

    Should I tag the code with [/QUOTE] in the thread?

    I appreciate your help.

  3. #3
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Macro fill the text in the specific column

    please try this code

    Dim r As Range
    Dim res As Range
    Set r = Range("B3", Range("E" & Rows.Count).End(xlUp))
    
    Set res = r.Find("")
    If Not res Is Nothing Then
        Do
            res.Value = res.Offset(-1, 0).Value
            Set res = r.FindNext(res)
        Loop Until res Is Nothing
    End If

  4. #4
    Forum Contributor
    Join Date
    04-29-2011
    Location
    South Korea
    MS-Off Ver
    Excel 2019
    Posts
    178

    Re: Macro fill the text in the specific column

    Quote Originally Posted by mohd9876 View Post
    please try this code

    Dim r As Range
    Dim res As Range
    Set r = Range("B3", Range("E" & Rows.Count).End(xlUp))
    
    Set res = r.Find("")
    If Not res Is Nothing Then
        Do
            res.Value = res.Offset(-1, 0).Value
            Set res = r.FindNext(res)
        Loop Until res Is Nothing
    End If
    Dear,
    I am sorry that I test the code in my attached excel, it doesn't work. The object viewer said. 'it doesn't work and the error message: invalid outside procedure at the code of
     Set r = Range("B3", Range("E" & Rows.Count).End(xlUp))

    Dim r As Range
    Dim res As Range
    Set r = Range("B3", Range("E" & Rows.Count).End(xlUp))
    
    Set res = r.Find("")
    If Not res Is Nothing Then
        Do
            res.Value = res.Offset(-1, 0).Value
            Set res = r.FindNext(res)
        Loop Until res Is Nothing
    End If
    Last edited by ronlau123; 05-23-2011 at 09:55 AM.

  5. #5
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Macro fill the text in the specific column

    where did you put the code??
    you must put it in the Table(before) worksheet in order for it to work.
    if you want to put it in a module please add the following line on the top of the code
    ActiveWorkbook.Worksheets("Table(before)").Activate

  6. #6
    Forum Contributor
    Join Date
    04-29-2011
    Location
    South Korea
    MS-Off Ver
    Excel 2019
    Posts
    178

    Re: Macro fill the text in the specific column

    Quote Originally Posted by mohd9876 View Post
    where did you put the code??
    you must put it in the Table(before) worksheet in order for it to work.
    if you want to put it in a module please add the following line on the top of the code
    ActiveWorkbook.Worksheets("Table(before)").Activate
    Dear,

    I insert in new module. It still can't work. I attached the file, would you mind help me to change. I believe I do something wrong, I tried to put the sentence in different statement......Thanks.

    ActiveWorkbook.Worksheets("Table(before)").Activate
    Dim r As Range
    Dim res As Range
    Set r = Range("B3", Range("E" & Rows.Count).End(xlUp))
    Set res = r.Find("")
    If Not res Is Nothing Then
        Do
            res.Value = res.Offset(-1, 0).Value
            Set res = r.FindNext(res)
        Loop Until res Is Nothing
    End If

  7. #7
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Macro fill the text in the specific column

    Dude you are putting the code without a sub !!!!!!
    I thought you already knew that..
    it has to be like this:
    
    Sub FillInBlanks()
    ActiveWorkbook.Worksheets("Table(before)").Activate
    Dim r As Range
    Dim res As Range
    Set r = Range("B3", Range("E" & Rows.Count).End(xlUp))
    Set res = r.Find("")
    If Not res Is Nothing Then
        Do
            res.Value = res.Offset(-1, 0).Value
            Set res = r.FindNext(res)
        Loop Until res Is Nothing
    End If
    End Sub
    HTH
    mohammad

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1