Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Populating data from SQL server to excel

Posted on 2011-09-27
4
Medium Priority
?
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

609 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