Consulting

Results 1 to 7 of 7

Thread: dividing numbers & blank rows

  1. #1

    dividing numbers & blank rows

    [VBA]Dim x As Integer

    Sheets("Sheet2").Select
    Range("K3").Select

    Do While IsEmpty(ActiveCell.Offset(0, 0)) = False

    x = ActiveCell.FormulaR1C1
    x = x / 100
    ActiveCell.FormulaR1C1 = x

    ActiveCell.Offset(1, 0).Select[/VBA]

    However, when the active cell has like a few decimal places, then when I divide by 100 it ends up giving me an integer (i still want decimal places!).
    I tried declaring x as long etc but that did not help.

    2. I have certain rows of data (J3:M3) and the rows go from 3,4,5... etc and it is not known at what row they stop. If I have blank rows...how can i get vba to move the next available row of data up...so that there are no blank rows?

  2. #2
    VBAX Mentor anandbohra's Avatar
    Joined
    May 2007
    Location
    Mumbai
    Posts
    313
    Location
    try this it will divide all the values with 100 which u selected in inputbox


    [VBA]Sub div_by_100()
    Dim selrange As Range
    Dim xval
    Set selrange = Application.InputBox("Select Data range", , Selection.Address, , , , , 8)
    For Each xval In selrange
    xval.Value = xval / 100
    Next xval
    End Sub[/VBA]
    Always Mark your Thread as Solved the moment u got acceptable reply (located under Thread tools)
    Practice this & save time of others in thinking for unsolved thread

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Both Long and Integer only take mathematical integer {..,-2,-1,0,1,2,..}) values.

    Declare x as Double and it will work right.

    Single is seldom used, but will also handle fractional values.


    Range("J65536").End(xlUp) will return the last filled cell in column J.

  4. #4
    I'm not quite clear on the "Range("J65536").End(xlUp) will return the last filled cell in column J." part.


    Can you elaborate on that plz.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It means that it does a search up from the bottom row untiil it finds a non-blank cell. So it doesn't matter about blank rows before the last filled cell.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    ok but how can i work that into some code which will automatically get rid of the blank rows

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim rng As Range

    With ActiveSheet

    Set rng = .Range(.Range("J1"), .Range("J" & .Rows.Count).End(xlUp))
    On Error Resume Next
    Set rng = rng.SpecialCells(xlCellTypeBlanks)
    On Error GoTo 0
    If Not rng Is Nothing Then rng.EntireRow.Delete
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •