Consulting

Results 1 to 4 of 4

Thread: Solved: Setting Variable Equal to Cell Value

  1. #1
    VBAX Regular
    Joined
    Aug 2006
    Posts
    36
    Location

    Solved: Setting Variable Equal to Cell Value

    Hoping this is easy ... I'm having a problem setting integer variable Model equal to the value of a cell. I've highlighted the specific section in blue. For background, I'm trying to add labeling based on a specific order of blank and non-blank cells.

    Thanks.

    Dim Model As Integer

    iRow = 7

    Do Until iRow = 500

    If IsEmpty(Cells(iRow, 34)) = False And _
    IsEmpty(Cells(iRow + 1, 34)) = True And _
    IsEmpty(Cells(iRow + 2, 34)) = True Then
    iRow = iRow + 1
    ElseIf IsEmpty(Cells(iRow, 34)) = True And _
    IsEmpty(Cells(iRow + 1, 34)) = True And _
    IsEmpty(Cells(iRow + 2, 34)) = False Then
    iRow = iRow + 1
    ElseIf IsEmpty(Cells(iRow, 34)) = True And _
    IsEmpty(Cells(iRow + 1, 34)) = False And _
    IsEmpty(Cells(iRow + 2, 34)) = False Then

    Model = Cells(iRow, 34)
    Select Case Model
    Case Model = 15000
    Range("B" & iRow).Select
    ActiveCell.FormulaR1C1 = "Blue"
    Selection.Font.Bold = True
    Case Model = 5670
    Range("B" & iRow).Select
    ActiveCell.FormulaR1C1 = "Red"
    Selection.Font.Bold = True
    End Select
    iRow = iRow + 1
    ElseIf IsEmpty(Cells(iRow, 34)) = False And _
    IsEmpty(Cells(iRow + 1, 34)) = False And _
    IsEmpty(Cells(iRow + 2, 34)) = False Then
    iRow = iRow + 1
    ElseIf IsEmpty(Cells(iRow, 34)) = False And _
    IsEmpty(Cells(iRow + 1, 34)) = False And _
    IsEmpty(Cells(iRow + 2, 34)) = True Then
    iRow = iRow + 1
    ElseIf IsEmpty(Cells(iRow, 34)) = True And _
    IsEmpty(Cells(iRow + 1, 34)) = False And _
    IsEmpty(Cells(iRow + 2, 34)) = True Then
    iRow = iRow + 1
    ElseIf IsEmpty(Cells(iRow, 34)) = True And _
    IsEmpty(Cells(iRow + 1, 34)) = True And _
    IsEmpty(Cells(iRow + 2, 34)) = True Then
    iRow = 500
    End If
    Loop

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

    Dim Model As Long

    iRow = 7
    Do Until iRow = 500

    If Not IsEmpty(Cells(iRow, 34)) And _
    IsEmpty(Cells(iRow + 1, 34)) And _
    IsEmpty(Cells(iRow + 2, 34)) Then

    iRow = iRow + 1
    ElseIf IsEmpty(Cells(iRow, 34)) And _
    IsEmpty(Cells(iRow + 1, 34)) And _
    Not IsEmpty(Cells(iRow + 2, 34)) Then

    iRow = iRow + 1
    ElseIf IsEmpty(Cells(iRow, 34)) And _
    Not IsEmpty(Cells(iRow + 1, 34)) And _
    Not IsEmpty(Cells(iRow + 2, 34)) Then

    Select Case Cells(iRow, 34).Value

    Case 15000
    With Range("B" & iRow)
    .FormulaR1C1 = "Blue"
    .Font.Bold = True
    End With

    Case 5670
    With Range("B" & iRow)
    .FormulaR1C1 = "Red"
    .Font.Bold = True
    End With
    End Select
    iRow = iRow + 1
    ElseIf Not IsEmpty(Cells(iRow, 34)) And _
    Not IsEmpty(Cells(iRow + 1, 34)) And _
    Not IsEmpty(Cells(iRow + 2, 34)) Then

    iRow = iRow + 1
    ElseIf Not IsEmpty(Cells(iRow, 34)) And _
    Not IsEmpty(Cells(iRow + 1, 34)) And _
    IsEmpty(Cells(iRow + 2, 34)) Then

    iRow = iRow + 1
    ElseIf IsEmpty(Cells(iRow, 34)) And _
    Not IsEmpty(Cells(iRow + 1, 34)) And _
    IsEmpty(Cells(iRow + 2, 34)) Then

    iRow = iRow + 1
    ElseIf IsEmpty(Cells(iRow, 34)) And _
    IsEmpty(Cells(iRow + 1, 34)) And _
    IsEmpty(Cells(iRow + 2, 34)) Then

    iRow = 500
    End If
    Loop
    [/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

  3. #3
    VBAX Regular
    Joined
    Aug 2006
    Posts
    36
    Location
    That did it ... thanks.
    Also, I got rid of the variable Model -- no longer required.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by ajrob
    Also, I got rid of the variable Model -- no longer required.
    True, hardly worth using a variable if it is only used once.
    ____________________________________________
    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
  •