locked
VBA Range with 2 conditions RRS feed

  • Question

  • Part of my invoice generator code is to move data from the invoice template to another worksheet. However, some products do not have barcodes of which I need to have a code to run with separately. 

    So far the code below is what I tried but seems not working. 

    I would Like that whenever each cell between b20 to b32 = a then it runs the <g class="gr_ gr_15 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" data-gr-id="15" id="15">codeA</g> otherwise if a cell between b20 to b32 = b then it will run the <g class="gr_ gr_16 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" data-gr-id="16" id="16">codeB</g>.

    my other option is to write a code for each cell between b20 to b32 but my code is very long and I have 8 cells to check if its value is = a or b. 

    please help. Thank you

           Private Sub Testfor()
                    Dim cell As Range
                    Dim r As Long
                    Dim pd As Range
                    
                    r = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
                    Set pd = Sheet1.Range("B20:B32")
                    For Each cell In pd
                    
                    If cell = "DP" Or cell = "TA" Then
                    
                    Sheet2.Cells(r, 1) = "yes"
                    Sheet2.Cells(r, 2) = "yes"
                    Sheet2.Cells(r, 3) = "yes"
                    
                    ElseIf cell = "FM" Or cell = "PM" Or cell = "FC" Then
                    
                    Sheet2.Cells(r, 1) = "K"
                    Sheet2.Cells(r, 2) = "v"
                    Sheet2.Cells(r, 3) = "c"
                     
                    End If
                     
                     Next cell
                     
                    
                     
                    End Sub

    Sunday, September 16, 2018 6:41 PM

All replies

  • This appears to be an Excel question. Post it there, rather than in this Access database forum.

    -Tom. Microsoft Access MVP

    Sunday, September 16, 2018 7:43 PM
  • I think

                    r = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

    should be

                    r = Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(1, 0).Row


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Sunday, September 16, 2018 7:45 PM