+ Reply to Thread
Results 1 to 15 of 15

How to fill blank cells with values in other column?

  1. #1
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    779

    How to fill blank cells with values in other column?

    Hi all,

    Hope all going good.

    In attached file, there's a macro in module 4 whose step 2 doesn't work properly.

    My requirement is that if there are blank cells in column J (upto last row of column A), then those blank cells should be filled with the corresponding row value of column Q. But macro still gives blanks.

    Can someone please check what's wrong with the code.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to fill blank cells with values in other column?


    Hi,

    'cause the cells are not 'blank' like you can check yourself with an easy Excel formula …

  3. #3
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    779

    Re: How to fill blank cells with values in other column?

    @Marc L

    Thanks for your response Marc.

    Sorry i forgot to mention the initial steps.

    The sheet "SAP Data" will be cleared and the the entire data form sheet "Raw Data" will be pasted in sheet "SAP Data" post which macro will run.

    Columns before running, macro will be J / Q and post macro will become I / P.

    Could you please help with modifying the code such that the cells that appear blank in Column J (upto data till last row in column A) should be filled with the corresponding row values of column Q.

    Thank you.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: How to fill blank cells with values in other column?


    From where comes the Raw Data worksheet data ?!

  5. #5
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    779

    Re: How to fill blank cells with values in other column?

    The data in sheet "Raw Data" will be downloaded from external source and directly pasted in sheet "SAP Data".

    I have given the sheet "Raw Data" just for reference. In actual, the sheet wont exist.

  6. #6
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: How to fill blank cells with values in other column?

    Because the cells in column J appear to be empty, but there is actually a space.
    Therefore, the condition for J is either empty or contains a space
    PHP Code: 
    ' Step 2: Fill blank cells in column J with values from column Q
        Dim LastRow As Long
        LastRow = Cells(Rows.Count, "J").End(xlUp).Row
        For i = 2 To LastRow
            If IsEmpty(Cells(i, "J")) Or AscW(Cells(i, "J")) = 32 Then ' 
    add 1 more condition here
                Cells
    (i"J").Value Cells(i"Q").Value
            End 
    If
        
    Next i 
    Quang PT

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to fill blank cells with values in other column?


    Quote Originally Posted by rizwanulhasan View Post
    The data in sheet "Raw Data" will be downloaded from external source and directly pasted in sheet "SAP Data".
    So seems to be badly imported !
    As the obvious efficient is to correct the import in order there is nothing to do 'after' …
    Or why don't you just copy directly column Q to column J ? Just with a single codeline !

  8. #8
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    779

    Re: How to fill blank cells with values in other column?

    @bebo

    Thanks for the help. But post running the code, it still shows blank.

    @Marc

    No Marc, cant copy entire column Q to J because some values are different between both columns and therefore only blank cells in column J needs to be filled.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to fill blank cells with values in other column?


    It's what happens with bad attachment not well reflecting the real workbook, what could you expect proceeding like this ? …

  10. #10
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    779

    Re: How to fill blank cells with values in other column?

    Guess this is working

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to fill blank cells with values in other column?


    I guess so, just hoping the worksheet as few data rows … Can be achieved without any loop just with an Excel basics formula …

  12. #12
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    779

    Re: How to fill blank cells with values in other column?

    Quote Originally Posted by Marc L View Post

    It's what happens with bad attachment not well reflecting the real workbook, what could you expect proceeding like this ? …
    Agree Marc. But that's how the extract is downloaded. I do not have any option to change it

  13. #13
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    779

    Re: How to fill blank cells with values in other column?

    Thanks all for your help. Greatly appreciated

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: How to fill blank cells with values in other column?


    (removed as my bad)
    Last edited by Marc L; 09-12-2023 at 05:22 AM.

  15. #15
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: How to fill blank cells with values in other column?

    Quote Originally Posted by rizwanulhasan View Post
    @bebo
    Thanks for the help. But post running the code, it still shows blank.
    It works for me
    BTW, your code should be shorter, like this:
    PHP Code: 
    Sub FormatAndCleanData()
        
    ' Activate the "SAP Data" sheet from the "Main_Page"
        Sheets("SAP Data").Activate
        
        ' 
    Step 1Format column "A" to system date
        Columns
    ("A").NumberFormat "dd-mm-yyyy"
        
        ' Step 2: Fill blank cells in column J with values from column Q
        Dim LastRow As Long
        LastRow = Cells(Rows.Count, "J").End(xlUp).Row
        For i = 2 To LastRow
            If IsEmpty(Cells(i, "J")) Or AscW(Cells(i, "J")) = 32 Then
                Cells(i, "J").Value = Cells(i, "Q").Value
            End If
        Next i
        
        ' 
    Step 3Delete columns "B""AA", and "AD"
        
    Range("B1,AA1,AD1").EntireColumn.Delete
        
        
    ' Step 4: Center align all columns
        Cells.HorizontalAlignment = xlCenter
        
        ' 
    Step 5Fit width of all columns except column "U"
         
    ActiveSheet.UsedRange.Columns.AutoFit
         Columns
    ("U").ColumnWidth Columns("XFD").ColumnWidth ' set defaul width
        
        ' 
    Step 6Go to cell A1
        Range
    ("A1").Select
        
        
    ' Step 7: Go to sheet "Main_Page" and give a pop-up message
        Sheets("Main_Page").Activate
        MsgBox "Done"
    End Sub 

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] fill blank cells in a column by duplicating values of first unique instance
    By hasan mougharbel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-11-2021, 03:46 AM
  2. [SOLVED] Fill blank cells in a column?
    By NicholasLag in forum Excel General
    Replies: 9
    Last Post: 08-21-2015, 05:30 AM
  3. [SOLVED] Macro to fill blank cells in column A based on non-blank cells
    By ktalamantez in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-28-2014, 02:47 PM
  4. Replies: 1
    Last Post: 04-11-2013, 01:02 PM
  5. How to fill blank cells with different values in a column
    By intermine in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-05-2010, 12:43 AM
  6. Help: How do I fill a column with values if it is blank?
    By limshady411 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-14-2005, 05:45 PM
  7. [SOLVED] how can i fill blank cells in column with abc while the right col.
    By khurram saddique in forum Excel General
    Replies: 2
    Last Post: 02-12-2005, 12:06 PM

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