Results 1 to 13 of 13

Loop and IF help

Threaded View

  1. #1
    Registered User
    Join Date
    10-12-2011
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2003
    Posts
    13

    Loop and IF help

    Hello, I am a newbie to VBA and I know I will make some people cringe when you read my code. I am trying to set up a macro that will copy data from a input workbook, paste into an application, then paste into another output workbook.

    I am trying to take baby steps for now, I need to set up the part where I can take data from a spreadsheet thats populated in columns A:F, and a variable number of rows.

    I want the macro to start on cell A2 and work its way to F2, then move to the next row, etc (The paste in application and paste into output file I will handle later)

    I think I am hitting trouble in 2 areas:
    1) setting up the declarations
    2) the intersect (If (R,C) is in Col A, I need to paste it into a particular field in the application, same for each other column)

    Sub test()
      Dim LastRow As Long, LastCol As Integer, c As Integer, r As Long
      Set Office = Columns("A")
      Set Account = Columns("B")
      Set AT = Columns("C")
      Set Journal = Columns("D")
      Set Sign = Columns("E")
      Set Desc = Columns("F")
      
        LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
        LastCol = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
         
        For r = 1 To LastRow
            For c = 1 To LastCol
                If Intersect(Cells(r, c), Office) Then
                     'Paste into application
                     'Paste into output
                End If
                If Intersect(Cells(r, c), Account) Then
                     'Paste into application
                     'Paste into output
                End If
                If Intersect(Cells(r, c), AT) Then
                     'Paste into application
                     'Paste into output
                End If
                If Intersect(Cells(r, c), Journal) Then
                     'Paste into application
                     'Paste into output
                End If
                If Intersect(Cells(r, c), Sign) Then
                     'Paste into application
                     'Paste into output
                End If
                If Intersect(Cells(r, c), Desc) Then
                     'Paste into application
                     'Paste into output
                End If
            c = c + 1
            Next c
        r = r + 1
        Next r
    End Sub

    Any help would be greatly appreciated!
    Last edited by mgnickel; 04-17-2012 at 09:27 PM. Reason: tags

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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