Results 1 to 5 of 5

Finding and Setting Columns

Threaded View

ashleys.nl Finding and Setting Columns 10-05-2011, 08:43 AM
StephenR Re: Finding and Setting... 10-05-2011, 08:49 AM
ashleys.nl Re: Finding and Setting... 10-05-2011, 09:09 AM
StephenR Re: Finding and Setting... 10-05-2011, 09:53 AM
ashleys.nl Re: Finding and Setting... 10-05-2011, 09:58 AM
  1. #1
    Registered User
    Join Date
    09-05-2011
    Location
    St. John's, Canada
    MS-Off Ver
    Excel 2010
    Posts
    70

    Finding and Setting Columns

    Hey Everyone,

    I've got columns labelled using two seperate cells. I want to find these columns using a macro so that I can then copy and paste certain rows of information from these columns. The only problem is since the columns are labelled using two cells sometimes key words repeat. So I have tried to create a search and check. However when I try to paste data using methods I have used in the past it doesn't seem to work. I get Run Time Error '1004' Application-Defined or object defined error.

    I know I've probably explained this poorly so I've attached a work book and the code below.

    Thanks for help in advance

    Sub DoubleColumn()
    
    Dim AllocOil As Range
    Dim Oil As String
    Dim ColAllocOil As Long
    
    Set AllocOil = Worksheets("Sheet1").Range("A5:Q8").Cells.Find(What:="Alloc", LookIn:=xlFormulas, LookAt:=xlWhole, _
                           SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, _
                           SearchFormat:=False)
    For i = 1 To 10
    
    If AllocOil.Offset(1, 0) = "oil" Then
    
    ColAllocOil = AllocOil.Column
    Exit For
    
    Else
    Set AllocOil = Worksheets("Sheet1").Range("A5:Q8").Cells.FindNext(After:=AllocOil)
    End If
    
    Next i
    
    Worksheets("Sheet1").Cells(1, "A").Value = Worksheets("Sheet1").Cells(8, ColAllocOil).Value
    
    End Sub
    Attached Files Attached Files
    Last edited by ashleys.nl; 10-05-2011 at 09:58 AM. Reason: Attached a better excel file - Solved

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