|
-
Aug 26th, 2018, 09:33 AM
#1
Thread Starter
Hyperactive Member
Increment Row after paste from clipboard
Help please... I am wanting to put the data from a datagridview into an excel spread sheet.
I can to the headers and all correectly and they get placed on Row 2
However in my datagrid loop
RowNum = 3
NumRecs = DataGridView1.Rows.Count.ToString()
Rnum = 0
For Each r In DataGridView1.Rows
TheRange = "A" + (RowNum.ToString & ",Z")
xlSheet.Range(TheRange, TheRange).Select()
WrkStr = r.Cells("NameOut").Value.ToString()
WrkStr = WrkStr + vbTab + r.Cells("EMAilOut").Value.ToString()
WrkStr = WrkStr + vbTab
Clip.SetDataObject(WrkStr)
xlSheet.Paste(misValue, misValue)
RowNum = RowNum + 1
Rnum = Rnum + 1
If Rnum = (NumRecs - 1) Then
Exit For
End If
Next
xlRange = xlSheet.Columns
xlRange.AutoFit()
EVERYLINE line added is in row 1 ..... How do I get it to go row 4 thru row xxxxx ?????
Thanks
gollnick
-
Aug 26th, 2018, 04:07 PM
#2
Re: Increment Row after paste from clipboard
you can try like
Code:
RowNum = 3
NumRecs = DataGridView1.Rows.Count.ToString()
Rnum = 0
For Each r In DataGridView1.Rows
WrkStr = r.Cells("NameOut").Value.ToString()
WrkStr = WrkStr + vbTab + r.Cells("EMAilOut").Value.ToString()
WrkStr = WrkStr + vbTab
Clip.SetDataObject(WrkStr)
xlSheet.cells(rownum, 1).Pastespecial
RowNum = RowNum + 1
Rnum = Rnum + 1
If Rnum = (NumRecs - 1) Then
Exit For
End If
Next
xlRange = xlSheet.Columns
xlRange.AutoFit()
though there are several variables that i am unsure what are used for
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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
|