Solved

Populating data from SQL server to excel

Posted on 2011-09-27
4
275 Views
Last Modified: 2012-05-12
Hi,

I need help on importing data from database to excel.

In excel file, there is a cell (A1 to A4,merged into one) named "ZZZ2".

In c# code after getting the data from database, i used the following code:

Clipboard.SetText(taxyear1_month.ToString());
xlWorkSheet.Paste(xlWorkSheet.get_Range("ZZZ2", "ZZZ2"), false);


It is not working. But if I name a single cell B4 as "zzz5" and use the code:
Clipboard.SetText(taxyear1_month.ToString());
xlWorkSheet.Paste(xlWorkSheet.get_Range("zzz5", "zzz5"), false);
It works.


Please help me to populate data into the merged cell


Regards
0
Comment
Question by:sam000
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:omgang
ID: 36711545
Both of these tests work for me

Public Function UpdateRange()
'assign value from a cell to a range of merged cells
On Error GoTo Err_UpdateRange

    Dim strValue As String

    strValue = Me.Cells(16, 11).Value
        'ZZZ2 refers to A1:A4 which are merged
    Me.Range("ZZZ2").Value = strValue

Exit_UpdateRange:
    Exit Function

Err_UpdateRange:
    MsgBox Err.Number & " (" & Err.Description & ") in procedure UpdateRange of VBA Document Sheet1"
    Resume Exit_UpdateRange

End Function


Public Function UpdateRange()
'copy value from a cell and paste into a range of merged cells
On Error GoTo Err_UpdateRange
   
    Me.Range("k16", "k16").Copy
   
    Me.Range("ZZZ2", "ZZZ2").PasteSpecial (xlPasteAll)

Exit_UpdateRange:
    Exit Function

Err_UpdateRange:
    MsgBox Err.Number & " (" & Err.Description & ") in procedure UpdateRange of VBA Document Sheet1"
    Resume Exit_UpdateRange

End Function

OM Gang
0
 

Author Comment

by:sam000
ID: 36711565
Could you please tell me a c# reference?
0
 
LVL 28

Accepted Solution

by:
omgang earned 500 total points
ID: 36711829
Try

String sValue = taxyear1_month.ToString();
xlWorkSheet.Range("ZZZ2", "ZZZ2").Value = sValue;

OM Gang
0
 

Author Closing Comment

by:sam000
ID: 37016040
helped a lot
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now