Solved

Populating data from SQL server to excel

Posted on 2011-09-27
4
283 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

820 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