PC Review


Reply
Thread Tools Rate Thread

Code won't fill to last row in table

 
 
Sabosis
Guest
Posts: n/a
 
      16th Oct 2009
Hello-

I have a code to fill all blanks in column F with an "X". There is
data in Columns A:E down to row 2145, but the code only puts the X
down to row 2135. Cell 2136 is the last filled cell in column F, this
has something to do with it. I want the code to search column F based
on the entire range of column E, in this case E2:E2145.

Sub b()

Dim lngLastRow As Long

Application.ScreenUpdating = False

For lngLastRow = Cells(Cells.Rows.Count, "F").End(xlUp).Row To 2
Step -1
If Cells(lngLastRow, "F") = "" Then
Cells(lngLastRow, "F").Value = "X"
End If
Next lngLastRow

Application.ScreenUpdating = True


End Sub

Please help if possible
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      16th Oct 2009
Hi

Your code has to look at column E, when it determine last row:

For lngLastRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row To 2 Step -1

It can also be done with this one line:

Sub FillX()
Range("F2", Range("F" &
Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks) = "X"
End Sub

Regards,
Per

"Sabosis" <(E-Mail Removed)> skrev i meddelelsen
news:68b4d055-d948-47a7-9e32-(E-Mail Removed)...
> Hello-
>
> I have a code to fill all blanks in column F with an "X". There is
> data in Columns A:E down to row 2145, but the code only puts the X
> down to row 2135. Cell 2136 is the last filled cell in column F, this
> has something to do with it. I want the code to search column F based
> on the entire range of column E, in this case E2:E2145.
>
> Sub b()
>
> Dim lngLastRow As Long
>
> Application.ScreenUpdating = False
>
> For lngLastRow = Cells(Cells.Rows.Count, "F").End(xlUp).Row To 2
> Step -1
> If Cells(lngLastRow, "F") = "" Then
> Cells(lngLastRow, "F").Value = "X"
> End If
> Next lngLastRow
>
> Application.ScreenUpdating = True
>
>
> End Sub
>
> Please help if possible


 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      16th Oct 2009
Then change the "F" in your in the For statement to "E". However, you don't
have to loop to do this; the following should do what you want...

Sub AssignXs()
Range("F2:F" & Cells(Rows.Count, "E").End(xlUp).Row). _
SpecialCells(xlCellTypeBlanks).Value = "X"
End Sub

--
Rick (MVP - Excel)


"Sabosis" <(E-Mail Removed)> wrote in message
news:68b4d055-d948-47a7-9e32-(E-Mail Removed)...
> Hello-
>
> I have a code to fill all blanks in column F with an "X". There is
> data in Columns A:E down to row 2145, but the code only puts the X
> down to row 2135. Cell 2136 is the last filled cell in column F, this
> has something to do with it. I want the code to search column F based
> on the entire range of column E, in this case E2:E2145.
>
> Sub b()
>
> Dim lngLastRow As Long
>
> Application.ScreenUpdating = False
>
> For lngLastRow = Cells(Cells.Rows.Count, "F").End(xlUp).Row To 2
> Step -1
> If Cells(lngLastRow, "F") = "" Then
> Cells(lngLastRow, "F").Value = "X"
> End If
> Next lngLastRow
>
> Application.ScreenUpdating = True
>
>
> End Sub
>
> Please help if possible


 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      16th Oct 2009
That will do what the OP's code does... but it is using the wrong "last
row"... the OP wants the last row in Column E to be applied to Column F's
range.

--
Rick (MVP - Excel)


"Per Jessen" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi
>
> Your code has to look at column E, when it determine last row:
>
> For lngLastRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row To 2 Step -1
>
> It can also be done with this one line:
>
> Sub FillX()
> Range("F2", Range("F" &
> Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks) = "X"
> End Sub
>
> Regards,
> Per
>
> "Sabosis" <(E-Mail Removed)> skrev i meddelelsen
> news:68b4d055-d948-47a7-9e32-(E-Mail Removed)...
>> Hello-
>>
>> I have a code to fill all blanks in column F with an "X". There is
>> data in Columns A:E down to row 2145, but the code only puts the X
>> down to row 2135. Cell 2136 is the last filled cell in column F, this
>> has something to do with it. I want the code to search column F based
>> on the entire range of column E, in this case E2:E2145.
>>
>> Sub b()
>>
>> Dim lngLastRow As Long
>>
>> Application.ScreenUpdating = False
>>
>> For lngLastRow = Cells(Cells.Rows.Count, "F").End(xlUp).Row To 2
>> Step -1
>> If Cells(lngLastRow, "F") = "" Then
>> Cells(lngLastRow, "F").Value = "X"
>> End If
>> Next lngLastRow
>>
>> Application.ScreenUpdating = True
>>
>>
>> End Sub
>>
>> Please help if possible

>


 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      16th Oct 2009
You are absolutely right.... Obviously I wasn't alert, when I changed it to
a single line statement....

--
Per

"Rick Rothstein" <(E-Mail Removed)> skrev i meddelelsen
news:(E-Mail Removed)...
> That will do what the OP's code does... but it is using the wrong "last
> row"... the OP wants the last row in Column E to be applied to Column F's
> range.
>
> --
> Rick (MVP - Excel)
>
>
> "Per Jessen" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Hi
>>
>> Your code has to look at column E, when it determine last row:
>>
>> For lngLastRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row To 2 Step -1
>>
>> It can also be done with this one line:
>>
>> Sub FillX()
>> Range("F2", Range("F" &
>> Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks) = "X"
>> End Sub
>>
>> Regards,
>> Per
>>
>> "Sabosis" <(E-Mail Removed)> skrev i meddelelsen
>> news:68b4d055-d948-47a7-9e32-(E-Mail Removed)...
>>> Hello-
>>>
>>> I have a code to fill all blanks in column F with an "X". There is
>>> data in Columns A:E down to row 2145, but the code only puts the X
>>> down to row 2135. Cell 2136 is the last filled cell in column F, this
>>> has something to do with it. I want the code to search column F based
>>> on the entire range of column E, in this case E2:E2145.
>>>
>>> Sub b()
>>>
>>> Dim lngLastRow As Long
>>>
>>> Application.ScreenUpdating = False
>>>
>>> For lngLastRow = Cells(Cells.Rows.Count, "F").End(xlUp).Row To 2
>>> Step -1
>>> If Cells(lngLastRow, "F") = "" Then
>>> Cells(lngLastRow, "F").Value = "X"
>>> End If
>>> Next lngLastRow
>>>
>>> Application.ScreenUpdating = True
>>>
>>>
>>> End Sub
>>>
>>> Please help if possible

>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Second fill in Ado.recordset does not fill table Jamal Samedov Microsoft ADO .NET 4 4th Sep 2010 02:00 PM
How to Fill a Table with Random Records from Another Table Telesphore Microsoft Access Queries 0 28th May 2005 03:29 PM
How do I automatically fill a column in a table using a ID code c. =?Utf-8?B?c2hyb29tdHVuZQ==?= Microsoft Access Getting Started 1 24th Mar 2005 03:01 PM
Fill automatic a table with the data of a queery table =?Utf-8?B?QW5kcmVhc00=?= Microsoft Access 3 14th Feb 2005 01:54 PM
Newbie needs help: how to fill in new table with any unchanged info from existing table Paul Simon Microsoft Access Queries 3 23rd Jul 2003 02:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:28 AM.