Filling Empty Cells in Excel

jmaxwell

New Member
Joined
Nov 19, 2010
Messages
16
Hi,

Row 2 cannot be empty before the last data of this row. I need a macro code that will fill in the empty cells before the last data in row 2 with "NA" with the exception if that row has the header "Phone" then I need it to fill that row only with "555555555" and the rest of the empty cell in row 2 with "NA" up until the last data of row 2. The goal here is not to have any empty cells in row 2 up before the last data of this row.

Example 1:
Column--------Header------- Data on row 2
A1------------ First Name ---- John
B1 ------------Last Name ----
C1 ----------- Phone -------- 818555333
D1 ------------State --------
E1 ------------File Num ------ 101

After running macro. Since the B2 and D2 is empty in this example, then B2 and D2 will be fill with "NA"
Column--------Header------- Data on row 2
A1------------ First Name ---- John
B1 ------------Last Name ---- NA
C1 ----------- Phone -------- 818555333
D1 ------------State -------- NA
E1 ------------File Num ------ 101
------------------------------------------------


Example 2: (empty under phone header)
Column--------Header------- Data on row 2
A1------------ First Name ---- John
B1 ------------Last Name ----
C1 ----------- Phone --------
D1 ------------State --------
E1 ------------File Num ------ 101

After running macro: In this example Cell B2, C2, and D2 are empty, then I need it to be fill with "NA" for B2 & D2 and "5555555555" for C2 since C2 is under the "phone" header.
Example 2 Results:
Column--------Header------- Data on row 2
A1------------ First Name ---- John
B1 ------------Last Name ---- NA
C1 ----------- Phone -------- 5555555555
D1 ------------State -------- NA
E1 ------------File Num ------ 101

I can send you a sample spreadsheet if I am not if I am not cleared. Any help will be appreciated. Thanks!
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
jmaxwell,

What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples directly in the forum.

Please attach screenshots of your workbook or a sample workbook that accurately portrays your current workbook on one sheet, and what it should look like 'After' on another sheet.

This makes it much easier to see exactly what you want to do, as well as shows us whether there is a consistent number of rows between tables and such.

Here are three possible ways to post small (copyable) screen shots directly in your post:

Please post a screenshot of your sheet(s), what you have and what you expect to achieve, with Excel Jeanie HTML 4 (contains graphic instructions).
http://www.excel-jeanie-html.de/html/hlp_schnell_en.php

or
RichardSchollar’s beta HTML Maker -...his signature block at the bottom of his post

or
Borders-Copy-Paste



If you are not able to give us screenshots:

To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

You can upload your workbook to www.box.net and provide us with a link to your workbook.
 
Upvote 0
jmaxwell,

Thanks for the workbook.


Sample raw data:


Excel Workbook
ABCDEFGHIJKL
1First NameLast NameM NameStatusAR AmountMobile PhonePhoneStateE-MailAddressCityZip Code
2AzitaWinterCurrent(343) 666-6443NVReno92688
3DaleSmithLynnCurrent$ 20.00(206) 423-3622(952) 111-6687CASenior@Gmail.ComPasenda2992
4DarrenSike30 days$ 50.00(203) 336-4266MS2486 Valley PlShelton6282
5FelixBrownJodyCurrent(344) 620-0003(203) 642-4333NVRgonzalez@Hotmail.Com96898
6JanetHackmannMcdondalCurrent$ 50.00(343) 322-6246CA66299
7JeriParkerJackCurrent(203) 642-4333CAParker.Jeri@Yahoo.Com5198 Moran StPerris95998
8JoeMendoza15 days$ 70.00(303) 663-2006(203) 336-4266TXMeperson@yahoo.ComWest Covina99989
9KarenLockheadRyanCurrent$ 80.00(342) 666-6303MIMiretta99996
10
Sample 1





After the macro:


Excel Workbook
ABCDEFGHIJKL
1First NameLast NameM NameStatusAR AmountMobile PhonePhoneStateE-MailAddressCityZip Code
2AzitaNAWinterCurrentNA(343) 666-6443(555) 555-5555NVNANAReno92688
3DaleSmithLynnCurrent$ 20.00(206) 423-3622(952) 111-6687CASenior@Gmail.ComPasenda2992
4DarrenSike30 days$ 50.00(203) 336-4266MS2486 Valley PlShelton6282
5FelixBrownJodyCurrent(344) 620-0003(203) 642-4333NVRgonzalez@Hotmail.Com96898
6JanetHackmannMcdondalCurrent$ 50.00(343) 322-6246CA66299
7JeriParkerJackCurrent(203) 642-4333CAParker.Jeri@Yahoo.Com5198 Moran StPerris95998
8JoeMendoza15 days$ 70.00(303) 663-2006(203) 336-4266TXMeperson@yahoo.ComWest Covina99989
9KarenLockheadRyanCurrent$ 80.00(342) 666-6303MIMiretta99996
10
Sample 1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub UpdateRow2()
' hiker95, 03/22/2011
' http://www.mrexcel.com/forum/showthread.php?t=538017
Dim LC As Long, a As Long
Application.ScreenUpdating = False
LC = Cells(1, Columns.Count).End(xlToLeft).Column
For a = 1 To LC Step 1
  If Cells(2, a) = "" Then
    If Cells(2, a).Offset(-1) = "Phone" Then
      With Cells(2, a)
        .Value = "5555555555"
        .HorizontalAlignment = xlCenter
        .NumberFormat = "[<=9999999]###-####;(###) ###-####"
        .Font.ColorIndex = 3
      End With
    Else
      With Cells(2, a)
        .Value = "NA"
        .HorizontalAlignment = xlCenter
        .Font.ColorIndex = 3
        .Font.Underline = xlUnderlineStyleNone
      End With
    End If
  End If
Next a
Application.ScreenUpdating = True
End Sub


Then run the UpdateRow2 macro.
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,229
Members
453,152
Latest member
ChrisMd

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