-
January 11th, 2019, 01:16 PM
#1
Excel Interop Help
Hey All,
I am having an issue returning an entire row of data rather then an individual cell. What am I doing wrong?
Code:
For i As Integer = 2 To counta
If CStr(xlWorkSheet2.Cells(i, 21).value) = Form3.Label1.Text Then
t1 = CStr(xlWorkSheet2.Cells(i, xlWorkSheet2.Range(i).EntireRow).Value)
xlWorkSheet2.
Form3.DataGridView1.Rows.Add(t1)
TextBox2.Text = "Row " & i
ProgressBar1.Value = ProgressBar1.Value + 1
Else
ProgressBar1.Value = ProgressBar1.Value + 1
End If
Next
Is there a way to return an entire row of data instead of just a cell?
Thanks!
Last edited by 2kaud; January 18th, 2019 at 05:41 AM.
Reason: formatting
-
January 11th, 2019, 06:21 PM
#2
Re: Excel Interop Help
Looks like the row you add only has one column (i.e. cell). I don't see code where you try to read.
Can you open an excell file and read the rows (search google for an example)? Try this to figure out if the issue is with how you add the row rather than reading a row.
-
January 17th, 2019, 06:39 PM
#3
Re: Excel Interop Help
Copying an entire row and pasting into another worksheet is not big deal. However, if I'm understanding correctly, this will work to capture an entire row as text values and allow you to paste them into a document. You would replace the hard coding of "U7" with your Form Label value and then this will search row i column 21 (i, 21). This is a mock-up to show you. I couldn't attach the workbook as an example.
Code:
Dim i As Integer
Dim intRow As Integer
Dim intCol As Integer
Dim rng As Variant
Dim str As String
Dim arr() As Variant
intRow = Range("A1").End(xlToRight).Column
intCol = Range("A1").End(xlDown).Row
For i = 1 To intRow
If Cells(i, 21) = "U7" Then
arr = Rows("1:1").Value
For Each rng In arr
str = str & " " & rng
Next
MsgBox str
End
End If
Next
Last edited by 2kaud; January 18th, 2019 at 05:42 AM.
-
January 17th, 2019, 06:44 PM
#4
Re: Excel Interop Help
Oops, replace the following... sorry.
Replace: arr = Row(1:1).Value
With arr = Rows(i & ":" & i).Value
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|