Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default While-Wend loop to fill in nulls

I'm trying to find any non-null cells in column f and then fill in any
null cell(s) below it with the value of that particular non-null cell
until it gets to the next non-null cell in column f. And, then repeat
this process for every non-null cell it until it gets to the end of my
overall data. I've created the code shown below, but it only partially
fills in the data; it only fills in one null cell below the non-null
cell. I'm sure I'm missing something obvious.

Dim h As Long
For h = Cells(1, "g").End(xlDown).Row To 1 Step -1
If Cells(h, "f") < "" Then
While Cells(h + 1, "f") = "" And Cells(h + 1, "g") < ""
Cells(h + 1, "f") = Cells(h, "f")
Wend
End If
Next h

Some sample data is as follows:
column f column g
xxx-xx-xxxx INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD
yyy-yy-yyyy INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD
zzz-zz-zzzz SOLTAX EARNINGS NO 3
TAXABLE FICA-SS YTD
TAXABLE FICA-HI YTD
TAX FEDERAL WITHHOLDING
TAX FICA-SS
TAX FICA-HI
SOLTAX DEDUCTION NO 1
999-99-999 SUPPL PAY

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default While-Wend loop to fill in nulls

Easier than you thought. Start from the top:

Sub marlie()
h = Cells(Rows.Count, "G").End(xlUp).Row
For i = 2 To h
Set r = Cells(i, "F")
If IsEmpty(r.Value) Then
r.FillDown
End If
Next
End Sub
--
Gary''s Student - gsnu2007


"tbmarlie" wrote:

I'm trying to find any non-null cells in column f and then fill in any
null cell(s) below it with the value of that particular non-null cell
until it gets to the next non-null cell in column f. And, then repeat
this process for every non-null cell it until it gets to the end of my
overall data. I've created the code shown below, but it only partially
fills in the data; it only fills in one null cell below the non-null
cell. I'm sure I'm missing something obvious.

Dim h As Long
For h = Cells(1, "g").End(xlDown).Row To 1 Step -1
If Cells(h, "f") < "" Then
While Cells(h + 1, "f") = "" And Cells(h + 1, "g") < ""
Cells(h + 1, "f") = Cells(h, "f")
Wend
End If
Next h

Some sample data is as follows:
column f column g
xxx-xx-xxxx INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD
yyy-yy-yyyy INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD
zzz-zz-zzzz SOLTAX EARNINGS NO 3
TAXABLE FICA-SS YTD
TAXABLE FICA-HI YTD
TAX FEDERAL WITHHOLDING
TAX FICA-SS
TAX FICA-HI
SOLTAX DEDUCTION NO 1
999-99-999 SUPPL PAY


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default While-Wend loop to fill in nulls

Debra Dalgleish shares a couple of ways to do this:
http://contextures.com/xlDataEntry02.html

Personally, unless this is a portion of a larger mechanized routine, I'd do it
manually. I think it's quicker to do than to find the code, modify it for a
specific column and run it.



tbmarlie wrote:

I'm trying to find any non-null cells in column f and then fill in any
null cell(s) below it with the value of that particular non-null cell
until it gets to the next non-null cell in column f. And, then repeat
this process for every non-null cell it until it gets to the end of my
overall data. I've created the code shown below, but it only partially
fills in the data; it only fills in one null cell below the non-null
cell. I'm sure I'm missing something obvious.

Dim h As Long
For h = Cells(1, "g").End(xlDown).Row To 1 Step -1
If Cells(h, "f") < "" Then
While Cells(h + 1, "f") = "" And Cells(h + 1, "g") < ""
Cells(h + 1, "f") = Cells(h, "f")
Wend
End If
Next h

Some sample data is as follows:
column f column g
xxx-xx-xxxx INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD
yyy-yy-yyyy INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD
zzz-zz-zzzz SOLTAX EARNINGS NO 3
TAXABLE FICA-SS YTD
TAXABLE FICA-HI YTD
TAX FEDERAL WITHHOLDING
TAX FICA-SS
TAX FICA-HI
SOLTAX DEDUCTION NO 1
999-99-999 SUPPL PAY


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default While-Wend loop to fill in nulls

On Oct 11, 8:42 pm, Dave Peterson wrote:
Debra Dalgleish shares a couple of ways to do this:http://contextures.com/xlDataEntry02.html

Personally, unless this is a portion of a larger mechanized routine, I'd do it
manually. I think it's quicker to do than to find the code, modify it for a
specific column and run it.



tbmarlie wrote:

I'm trying to find any non-null cells in column f and then fill in any
null cell(s) below it with the value of that particular non-null cell
until it gets to the next non-null cell in column f. And, then repeat
this process for every non-null cell it until it gets to the end of my
overall data. I've created the code shown below, but it only partially
fills in the data; it only fills in one null cell below the non-null
cell. I'm sure I'm missing something obvious.


Dim h As Long
For h = Cells(1, "g").End(xlDown).Row To 1 Step -1
If Cells(h, "f") < "" Then
While Cells(h + 1, "f") = "" And Cells(h + 1, "g") < ""
Cells(h + 1, "f") = Cells(h, "f")
Wend
End If
Next h


Some sample data is as follows:
column f column g
xxx-xx-xxxx INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD
yyy-yy-yyyy INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD
zzz-zz-zzzz SOLTAX EARNINGS NO 3
TAXABLE FICA-SS YTD
TAXABLE FICA-HI YTD
TAX FEDERAL WITHHOLDING
TAX FICA-SS
TAX FICA-HI
SOLTAX DEDUCTION NO 1
999-99-999 SUPPL PAY


--

Dave Peterson


I created an add-in that has a Fill Blanks routine. The first thing
it does is popup an input box asking for the column letter that is
then assigned to a variable and used throughout the code. It cycles
through that column until the last row of the spreadsheet is reached.
Of course, there may be times when it doesn't need to cycle through to
the last used row, but those times are so few and far between that I
found it more effective to just write it for the most common process.

I wrote it as a sub with a colLetter argument so that I can simply
call the sub whenever needed using the column letter as it's argument
such as fillBlanks "A". If this is something that you see yourself
routinely doing I strongly urge that you do the same. As Dave said,
it is very inefficient to have to modify the code constantly for
different scenarios.

Regards
-Jeff-

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default While-Wend loop to fill in nulls

On Oct 11, 5:59 pm, JW wrote:
On Oct 11, 8:42 pm, Dave Peterson wrote:





Debra Dalgleish shares a couple of ways to do this:http://contextures.com/xlDataEntry02.html


Personally, unless this is a portion of a larger mechanized routine, I'd do it
manually. I think it's quicker to do than to find the code, modify it for a
specific column and run it.


tbmarlie wrote:


I'm trying to find any non-null cells in column f and then fill in any
null cell(s) below it with the value of that particular non-null cell
until it gets to the next non-null cell in column f. And, then repeat
this process for every non-null cell it until it gets to the end of my
overall data. I've created the code shown below, but it only partially
fills in the data; it only fills in one null cell below the non-null
cell. I'm sure I'm missing something obvious.


Dim h As Long
For h = Cells(1, "g").End(xlDown).Row To 1 Step -1
If Cells(h, "f") < "" Then
While Cells(h + 1, "f") = "" And Cells(h + 1, "g") < ""
Cells(h + 1, "f") = Cells(h, "f")
Wend
End If
Next h


Some sample data is as follows:
column f column g
xxx-xx-xxxx INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD
yyy-yy-yyyy INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD
zzz-zz-zzzz SOLTAX EARNINGS NO 3
TAXABLE FICA-SS YTD
TAXABLE FICA-HI YTD
TAX FEDERAL WITHHOLDING
TAX FICA-SS
TAX FICA-HI
SOLTAX DEDUCTION NO 1
999-99-999 SUPPL PAY


--


Dave Peterson


I created an add-in that has a Fill Blanks routine. The first thing
it does is popup an input box asking for the column letter that is
then assigned to a variable and used throughout the code. It cycles
through that column until the last row of the spreadsheet is reached.
Of course, there may be times when it doesn't need to cycle through to
the last used row, but those times are so few and far between that I
found it more effective to just write it for the most common process.

I wrote it as a sub with a colLetter argument so that I can simply
call the sub whenever needed using the column letter as it's argument
such as fillBlanks "A". If this is something that you see yourself
routinely doing I strongly urge that you do the same. As Dave said,
it is very inefficient to have to modify the code constantly for
different scenarios.

Regards
-Jeff-- Hide quoted text -

- Show quoted text -


Thanks G.Student. That's what I needed

Dave/Jeff: Thanks for the input. I needed this code as part of a
larger routine.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
WEND in VBA Dave F Excel Discussion (Misc queries) 9 April 4th 23 10:37 AM
Loop and fill Question ram Excel Programming 5 October 21st 05 06:28 PM
Setting up a simple loop to fill labels? justchris[_2_] Excel Programming 5 August 23rd 05 12:50 PM
While ... Wend Andrzej Excel Programming 7 June 24th 05 08:03 PM
help on insert rows and fill down loop until end mark mcgrath Excel Programming 1 January 16th 04 01:50 AM


All times are GMT +1. The time now is 08:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"