This Formula Returns Blanks As Zeros, Can We Fix

rockyw

Well-known Member
Joined
Dec 26, 2010
Messages
1,196
Office Version
  1. 2010
Platform
  1. Windows
This formula works fine but it returns blanks as 0s, that messes up some condisional formating. I read where "" in the formula will stop the 0s from being returned? If so where would I insert them? Thanks
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, Range("P:P,B:B")) Is Nothing Then
        With ThisWorkbook
            .Sheets("Sheet2").Range("E3:E24").Value = .Sheets("Sheet3").Range("E3:E24").Value
        End With
    End If
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I have Excel 2007, windows 7 64 bit. If you have any other suggestions I would love to try it. Thanks
 
Upvote 0
For the return it just says 0 The condisional formating sees the 0 as a value and shows the text. If there is no value, the text stays white on a white background and I can not see it. Thanks
 
Upvote 0
Well, maybe uploading your file in any of the share sites and posting a link here might help.
 
Upvote 0
After some thought and help from SMC, I think now this may do:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Application.Intersect(Target, Range("P:P,B:B")) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>        <SPAN style="color:#00007F">With</SPAN> ThisWorkbook<br>            <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> .Sheets("Sheet3").Range("E3:E24")<br>            <SPAN style="color:#00007F">If</SPAN> c.Value <> 0 Then _<br>                Sheets("Sheet2").Range("E" & c.Row).Value = _<br>                .Sheets("Sheet3").Range("E" & c.Row).Value<br>            <SPAN style="color:#00007F">Next</SPAN> c<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

-Jeff
 
Upvote 0
Hey repairman! you fixed that!! Thanks it seems to work great. Now as more items numbers are added I will need to expand the range, E3 - E 26 ect. What in his code should I change to expand the range?
Code:
 For Each c In .Sheets("Sheet3").Range("E3:E26")
            If c.Value <> 0 Then _
                Sheets("Sheet2").Range("E" & c.Row).Value = _
                .Sheets("Sheet3").Range("E" & c.Row).Value
            Next c
Will changing to a 26 like I did here expand the range to E3 - E26? Thanks for the code.
 
Upvote 0
Glad to hear!

I did not test this next bit, but it is along the lines of something that should work for that.

Try:


<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Application.Intersect(Target, Range("P:P,B:B")) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>        <SPAN style="color:#00007F">With</SPAN> ThisWorkbook<br>            <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> .Sheets("Sheet3").Range("E3:E" & _<br>                    Range("E" & Rows.Count).End(xlUp).Row)<br>                <SPAN style="color:#00007F">If</SPAN> c.Value <> 0 Then _<br>                    Sheets("Sheet2").Range("E" & c.Row).Value = _<br>                    .Sheets("Sheet3").Range("E" & c.Row).Value<br>            <SPAN style="color:#00007F">Next</SPAN> c<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
So this code does not need edited to add rows? Thanks so much.
 
Upvote 0
Hello Rockyw,

Sorry I meant to clarify this more...

Yes you were right about being able to expand the code with the 'from 24 to 26' (hard-code). The newer code should automatically do that by looking for the last row for you.


Unless sheet 3 is not where the row count needs to happen, then yes
then the latest code would automatically adjust or be dynamic and would not need editing to expand rows.

If the row count should need to happen according to sheet2 then some adjustment will be needed.



What this is doing is using sheet3 range E3:E and the last row used.

Example= If the last row used on sheet3 in column E:E was row 24, it would loop through E3:E24 or if it was row 26 then E3:E26 and so forth.


Hope I have cleared any questions you had.

Let me know if the latest code seemed to work or if it needed any changes. I will be glad to help to the best of my ability.

Jeff
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,521
Members
452,923
Latest member
JackiG

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