+ Reply to Thread
Results 1 to 2 of 2

Macro Help. Looping, code change.

  1. #1
    Registered User
    Join Date
    01-27-2006
    Posts
    4

    Macro Help. Looping, code change.

    <EDIT, question answered>
    I needed to have one worksheet processed to grab data and add it to another worksheet in some format. Someone helped me figure it out. I'm posting the code below.

    Option Explicit
    Sub testme()
    Dim myCol1 As Range
    Dim myCol2 As Range
    Dim myCol3 As Range
    Dim myCell1 As Range
    Dim myCell2 As Range
    Dim myCell3 As Range
    Dim wks As Worksheet
    Dim newWks As Worksheet
    Dim oRow As Long
    Dim keyName As String
    Dim i As Long

    Set wks = Worksheets("Start->")

    With wks
    Set myCol1 = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
    Set myCol2 = .Range("c1", .Cells(.Rows.Count, "C").End(xlUp))
    Set myCol3 = .Range("b1", .Cells(.Rows.Count, "B").End(xlUp))
    If myCol1.Cells.Count * myCol2.Cells.Count > .Rows.Count Then
    MsgBox "Too much data!"
    Exit Sub
    End If
    End With

    Set newWks = Worksheets.Add

    oRow = 0
    i = 0
    For Each myCell1 In myCol1.Cells
    i = i + 1
    For Each myCell2 In myCol2.Cells
    oRow = oRow + 1
    With newWks.Cells(oRow, "A")
    keyName = myCell1.Value
    keyName = Replace(keyName, " ", "%20")
    .Value = "rule"
    .Offset(0, 1).Value = myCell1.Value & " ad=" & myCell2.Value
    .Offset(0, 2).Value = "<datamatch name=""ck""><![CDATA[" & keyName & "]]></datamatch><datamatch name=""ad""><![CDATA[" & myCell2.Value & "]]></datamatch>"
    .Offset(0, 3).Value = myCol3.Cells(i, 1)


    End With
    Next myCell2
    Next myCell1

    End Sub
    Last edited by TheDPQ; 01-30-2006 at 04:18 PM.

  2. #2
    Registered User
    Join Date
    01-27-2006
    Posts
    4
    I figured it out thanks to a lot of insanity and someone helping me on AIM.
    Last edited by TheDPQ; 01-30-2006 at 04:17 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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