Consulting

Results 1 to 2 of 2

Thread: Loop Conditional Statement through 2 columns and Copy/Paste from corresponding column

  1. #1

    Loop Conditional Statement through 2 columns and Copy/Paste from corresponding column

    Hello all,

    First of all I am a newby programmer who is trying to teach myself Excel VBA. I have a problem at work where I would like to create a macro to perform the steps listed below. Bascially running a conditional statement down the spreadsheet and if columns R and Q meet the condition copy/paste corresponding data from column F to the first open cell in Temp worksheet. I would really appreciate any help. This would be my first program and I cannot get it to work. Thanks

    Sub NewNumber()
    'Run Loop Through Column Q and R in Active Sheet, If column Q cell is
    ' "blank" and column R cell is "blank" or contains a "N" copy and paste
    ' Corresponding Column F cell into temp worksheet.

    Dim MyRange As Range
    'Varaible my range containing columns Q,R,and F


    For Each cell In MyRange("Q:Q" & "R:R" & "F:F")
    'For each cell in MyRange run loop

    If (Qcell = "" & Rcell = "N" Or "") Then Fcell.Select
    Selection.Copy
    Sheets("Temp").Range("A1").Select
    ActiveSheet.Paste

    'Paste contents into first cell in temp
    Next

    End Sub

    Thanks
    dmjackal_2000@yahoo.com

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

    Sub NewNumber()
    'Run Loop Through Column Q and R in Active Sheet, If column Q cell is
    ' "blank" and column R cell is "blank" or contains a "N" copy and paste
    ' Corresponding Column F cell into temp worksheet.

    Dim cell As Range
    Dim Target As Range

    Set Target = Sheets("Temp").Range("A1")
    For Each cell In Range(Range("F1"), Range("F1").End(xlDown))

    'Offset(0, 11) is Q, Offset(0,12) is Q
    If cell.Offset(0, 11).Value = "" And _
    (cell.Offset(0, 12).Value = "N" Or cell.Offset(0, 12).Value = "") Then

    cell.Copy Target
    Set Target = Target.Offset(1, 0)
    End If
    Next

    End Sub
    [/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
  •