Having some issues with my snippet of code...

eskelies

Board Regular
Joined
May 27, 2010
Messages
95
The following code keeps multiplying by a million instead of ending once the next cell is blank or has a zero. Do I need to have an offset? If so, how should it look?

Code:
          Set myRange = Range("B10:B20")
For Each c In myRange
        
        If IsNumeric(c) Then
            c.Value = c.Value * 1000000
        Else
            c.Value = ("")
        End If
Next
   For Each cell In [B11:B20]
If cell.Value = "0" Then cell.ClearContents
Next cell
Next
 
Range("A10:G20").Copy Destination:=Sheets("Sheet2").Range("H11")

any help would be useful.
 

Some videos you may like

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

xld

Banned
Joined
Feb 8, 2003
Messages
5,378
Code:
    For Each c In myRange
        
        If c.Value <> "" Then
        
            If IsNumeric(c.Value) Then
                c.Value = c.Value * 1000000
            Else
                c.Value = ("")
            End If
        End If
    Next
 

eskelies

Board Regular
Joined
May 27, 2010
Messages
95
nothing changed on this. It increases exponentially by a million instead of only increasing by a million once.
 
Last edited:

xld

Banned
Joined
Feb 8, 2003
Messages
5,378
If you REALLY want to end

Code:
    For Each c In myRange
        
        If c.Value <> "" Then
        
            If IsNumeric(c.Value) Then
                c.Value = c.Value * 1000000
            Else
                Exit For
            End If
        End If
    Next
 

eskelies

Board Regular
Joined
May 27, 2010
Messages
95

ADVERTISEMENT

Still isn't working properly. I'm getting exponentials to the 279th power.


If you REALLY want to end

Code:
    For Each c In myRange
 
        If c.Value <> "" Then
 
            If IsNumeric(c.Value) Then
                c.Value = c.Value * 1000000
            Else
                Exit For
            End If
        End If
    Next
 

Saffa84

New Member
Joined
Apr 29, 2010
Messages
19
The following code keeps multiplying by a million instead of ending once the next cell is blank or has a zero. Do I need to have an offset? If so, how should it look?

Code:
          Set myRange = Range("B10:B20")
For Each c In myRange
 
        If IsNumeric(c) Then
            c.Value = c.Value * 1000000
        Else
            c.Value = ("")
        End If
Next
   For Each cell In [B11:B20]
If cell.Value = "0" Then cell.ClearContents
Next cell
Next
 
Range("A10:G20").Copy Destination:=Sheets("Sheet2").Range("H11")

any help would be useful.
You original code works fine for me if I take out the extra "Next" at the end.
 

eskelies

Board Regular
Joined
May 27, 2010
Messages
95
Unfortunately for me it continuously multiplys by 1mm. Now it could be because that was only part of the code.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,595
Messages
5,512,304
Members
408,886
Latest member
kashifziatevta423

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top