Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:05:52+00:00 2026-06-13T04:05:52+00:00

Current problem: Target is to copy data from a source .csv file to a

  • 0

Current problem:

Target is to copy data from a source .csv file to a target excel sheet, based on matching a value from each row of the .csv to values in an excel sheet column, and then making the copy based on that to the correct cells in the excel sheet.

I’m gathering values to an array from a .csv file in a loop, comparing one of the values in the array to values in the target excel sheet column A, if a match happens, all the values in the array are to be copied to the corresponding row in the excel sheet.

I’m now getting a “Type mismatch” error when trying to compare the excel sheet’s cell values to the array value.

Here are the relevant bits of the code:

sfile="\\DFSpath\file1.csv"
smaster="\\DFSpath\file2.xlsx"

set xlapp = createobject("excel.application")

set wbtarget = xlapp.workbooks.open(smaster)

set tgtworksheet = wbtarget.worksheets("sheet1")

set usedRowsXP = tgtworksheet.UsedRange.Rows

dim fs,objTextFile
set fs=CreateObject("Scripting.FileSystemObject")
dim arrStr
set objTextFile = fs.OpenTextFile(sfile)

Do while NOT objTextFile.AtEndOfStream
  arrStr = split(objTextFile.ReadLine,",")

    for each oRow in usedRowsXP   

    Introw = oRow
    If tgtworksheet.cells(Introw,1).value = arrStr(2) Then
    tgtworksheet.cells(Introw,4).value = arrStr(0)
    tgtworksheet.cells(Introw,5).value = arrStr(1)
    tgtworksheet.cells(Introw,6).value = arrStr(2)

    End If
    next
Loop

Fixed by modifying the code as follows:

dim fs,objTextFile
    set fs=CreateObject("Scripting.FileSystemObject")
    dim arrStr
    set objTextFile = fs.OpenTextFile(sfile)

'##Replace quotation marks with nothing in .csv##

strText = objtextFile.ReadAll
objTextFile.Close
strNewText = Replace(strText, """", "")

Set objtextFile = fs.OpenTextFile(sfile, 2)
objtextFile.Write strNewText
objtextFile.Close

set objTextFile = fs.OpenTextFile(sfile, 1)

'##Gather array out of line in .csv + compare user's name to name in excel sheet, if matches, copy data, repeat for each line##


Do while NOT objTextFile.AtEndOfStream
arrStr = split(objTextFile.ReadLine,",")     

for each oRow in usedRowsXP   

Introw = oRow.row
If Cstr(tgtworksheet.cells(Introw,1).value) = arrStr(2) Then
tgtworksheet.cells(Introw,4).value = arrStr(0)
tgtworksheet.cells(Introw,5).value = arrStr(1)
tgtworksheet.cells(Introw,6).value = arrStr(2)

End If
next

Loop
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:05:53+00:00Added an answer on June 13, 2026 at 4:05 am

    I think the problem is in this row:

    for each oRow in usedRowsXP  
    Introw = oRow
    

    I’m not really good at VBA, but I think that usedRowsXP is a Range, and each row of it will also be a range. Therefore Introw will be a range. Try using the Row property of oRow, it will return its row number:

    for each oRow in usedRowsXP  
    Introw = oRow.Row 
    

    After that Introw should work fine in the Cells(Introw, 1) etc. expression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes
I'm stuck and can't figure out a fix to my current problem and was
I want to fix the Background while only the ListFields scrolls. Current Problem: Scrolling
I'm trying to write a re-usable .NET Assembly that implements WCF. My current problem
My problem is to get the current latitude and longitude of the user. I
authentication problem on windows vista (iis7) (cookie is getting written but httpcontext.current.user is null)
I have a problem with obtaining the current user location. Code at first works
I'm meeting some problem understanding how my current Payment Gateway( ProcessPink ) identify duplicate
The following code summarizes the problem I have at the moment. My current execution
I get a weird problem. Getting java.util.ConcurrentModificationException . But I'm not modifying the current

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.