+ Reply to Thread
Results 1 to 2 of 2

Dynamic Database copying

Hybrid View

hattisaeed Dynamic Database copying 08-24-2011, 01:25 AM
Steffen Thomsen Re: Dynamic Database copying 08-24-2011, 05:01 AM
  1. #1
    Registered User
    Join Date
    08-15-2011
    Location
    Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    38

    Dynamic Database copying

    hi i want to copy using dynamic range my code is as follows
    Sub FlowchartProcess1_Click()
      Dim wksQA           As Excel.Worksheet
       Dim wksEmp            As Excel.Worksheet
       Dim varColumn
           Dim Lastrow As Long
           Dim lastrow2 As Long
    
        Lastrow = Sheets("QA_Matrix").Range("c" & Rows.Count).End(xlUp).Row
        
        Sheets("ind").Range("b9:b" & Lastrow + 1000).ClearContents
    
        Sheets("ind").Range("b9:b" & Lastrow - 1).Value = Sheets("QA_matrix").Range("c11:c" & Lastrow).Value
    
    
    
    
       Set wksEmp = Sheets("ind")
       Set wksQA = Sheets("QA_Matrix")
    
       ' find employee column on matrix sheet
       varColumn = Application.Match(wksEmp.Range("C4").Value, wksQA.Range("7:7"), 0)
    lastrow2 = Sheets("QA_Matrix").Range("varColumn" & Rows.Count).End(xlUp).Row
       If IsError(varColumn) Then
          ' no match so display error message
          MsgBox "No match found for employee: " & strName
       Else
          ' copy employee data across
          wksQA.Range("varColumn11:varColumn" & Lastrow).Value = wksEmp.Range("b9:b" & Lastrow - 1).Value
        
       End If
    End Sub
    it gives object error i want to do something of this type using varColumn this works fine when using column c or some defined one i have attached the workbook
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Dynamic Database copying

    hi,

    Change this line

    
    varColumn = Application.Match(wksEmp.Range("C4").Value, wksQA.Range("7:7"), 0)
    to

    
    varColumn = wksQA.Cells.Find(what:=wksEmp.Range("C4").Value, SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
    Edit:
    Btw where do you set the value of strName?

    Steffen Thomsen

+ 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