syntax for ranges in macro
VBA Telemetry pings you when your VBA projects fail
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: syntax for ranges in macro

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Milwaukee, WI
    Posts
    105
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Can anyone help me with the syntax here?

    Sub Extract()
    SpreadsRow = 2
    For DataRow = 2 To LastRow 'defined earlier
    Set ADataRow = Sheets("Data").Range("J" & DataRow)
    Set BDataRow = Sheets("Data").Range("J" & DataRow)
    Set JDataRow = Sheets("Data").Range("J" & DataRow)
    Set ASpreadsRow = Sheets("Spreads").Range("A" & SpreadsRow)
    Set BSpreadsRow = Sheets("Spreads").Range("C" & SpreadsRow)
    Set CSpreadsRow = Sheets("Spreads").Range("C" & SpreadsRow)
    Set KDataRow = Sheets("Data").Range("J" & DataRow)


    If JDataRow.Value = "Average" Then
    If ASpreadsRow.Value = "" Then
    Range("BDataRow").Select
    Selection.Copy
    Range(ASpreadsRow).Select
    Selection.Paste
    End If
    If ASpreadsRow = BDataRow Then
    If ADataRow.Value = "L" Then
    Range(KDataRow).Select
    Selection.Copy
    Range(CSpreadsRow).Select
    Selection.Paste
    End If
    If ADataRow.Value = "B" Then
    Range(KDataRow).Select
    Selection.Copy
    Range(BSpreadsRow).Select
    Selection.Paste
    End If
    SpreadsRow = SpreadsRow + 1
    End If
    End If
    Next DataRow

    End Sub

  2. #2
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    What's your problem?

    I'm assuming from your variable names that there might be a problem with these lines of code:


    Set ADataRow = Sheets("Data").Range("J" & DataRow)
    Set BDataRow = Sheets("Data").Range("J" & DataRow)
    Set JDataRow = Sheets("Data").Range("J" & DataRow)
    Set ASpreadsRow = Sheets("Spreads").Range("A" & SpreadsRow)
    Set BSpreadsRow = Sheets("Spreads").Range("C" & SpreadsRow)
    Set CSpreadsRow = Sheets("Spreads").Range("C" & SpreadsRow)
    Set KDataRow = Sheets("Data").Range("J" & DataRow)


    If you were wanting to set "ADataRow", "BDataRow" etc to actually be in those columns (A, B etc) then you'd better changed the "J" in each of these to be "Range("A" & DataRow), etc...

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Location
    Milwaukee, WI
    Posts
    105
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Sorry, I realised i hadn't changed those after I posted.

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com