+ Reply to Thread
Results 1 to 3 of 3

fill empty with two condition

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-14-2010
    Location
    oman
    MS-Off Ver
    Excel 2003
    Posts
    384

    Post fill empty with two condition

    Sub Package()
     
    Dim CalculatedValue
    Range("L2").Select
    Do
        If ActiveCell.Value = "" Then
            CalculatedValue = Application.WorksheetFunction.RoundUp(ActiveCell.Offset(0, -1).Value / 1.5, 0) * 1.5
          Select Case CalculatedValue
          Case 61.5, 63: ActiveCell.Value = 64.5
                Case 31.5, 33: ActiveCell.Value = 34.5
                Case Else: ActiveCell.Value = CalculatedValue
                End Select
            End If
            ActiveCell.Offset(1, 0).Select
        Loop Until IsEmpty(ActiveCell.Offset(0, -2))
    End Sub
    dear friends above macro work fine for me.i need to add two conditions to that macro.it's like this.
    01.if Column "G" value " TP " & Column "H" value " 150D " then above 1.5 should change to 0.9
    CalculatedValue = Application.WorksheetFunction.RoundUp(ActiveCell.Offset(0, -1).Value / .9, 0) * .9
    02.if Column "G" value " PP " & Column "H" value " 16/2 " then above 1.5 should change to 1
    CalculatedValue = Application.WorksheetFunction.RoundUp(ActiveCell.Offset(0, -1).Value / 1, 0) * 1
    Column "G' & column "H" values other than above then 1.5 is correct.
    CalculatedValue = Application.WorksheetFunction.RoundUp(ActiveCell.Offset(0, -1).Value / 1.5, 0) * 1.5
    pls anybody can help me to do that......
    Last edited by johncena; 02-22-2010 at 04:28 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: fill empty with two condition

    Maybe this:
    Option Explicit
    
    Sub Package()
    Dim CalculatedValue As Double, Multi As Double
    
    Range("L2").Activate
    
    Do
        If ActiveCell.Value = "" Then
            If Cells(ActiveCell.Row, "G") = "TP" And Cells(ActiveCell.Row, "H") = "150D" Then
                Multi = 0.9
            ElseIf Cells(ActiveCell.Row, "G") = "PP" And Cells(ActiveCell.Row, "H") = "16/2" Then
                Multi = 1
            Else
                Multi = 1.5
            End If
            
            CalculatedValue = Application.WorksheetFunction.RoundUp(ActiveCell.Offset(0, -1).Value / 1.5, 0) * Multi
            
            Select Case CalculatedValue
                Case 61.5, 63: ActiveCell.Value = 64.5
                Case 31.5, 33: ActiveCell.Value = 34.5
                Case Else: ActiveCell.Value = CalculatedValue
            End Select
            
        End If
        
        ActiveCell.Offset(1, 0).Activate
    Loop Until IsEmpty(ActiveCell.Offset(0, -2))
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    02-14-2010
    Location
    oman
    MS-Off Ver
    Excel 2003
    Posts
    384

    Post Re: fill empty with two condition

    thank u very much JBeaucaire.your understanding is 100% correct,your macro very well.thanks a lot again....
    Last edited by johncena; 02-22-2010 at 04:28 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1