473,795 Members | 3,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

urgent: formatting XL cells

hi. im exporting data from a vb form to excel. i am able to create a new
excel file, save and edit it without any trouble, but the formatting is
giving me hell! i need to be able to show certain cells in bold, with
underlining etc. i dont understand how, but in the following code, the
instruction for bold gets picked up for all the cells (even when i specify
font.bold = false), and the underlining is haphazardly used. the font colour
formatting is also not getting picked up...
can someone please tell me how this thing works and what i should do?
With xlsheet
.Range("B1", "I50").RowHeigh t = 15
.Range("a1", "i50").ColumnWi dth = 8.43

'title of sheet
.Cells(1, 1).Font.ColorIn dex = 32
.Cells(1, 1).Style.font.s ize = 14
.Cells(1, 1).Font.Name = "Arial Black"
.Cells(1, 1).Value = "CONSUL"

'ISO form code
.Cells(2, 7).Font.ColorIn dex = 1
.Cells(2, 7).Style.font.s ize = 10
MsgBox("ISO CODE")
.Cells(2, 7).Style.font.b old = True
.Cells(2, 7).style.font.u nderline = False
.Cells(2, 7).Font.Name = "Batang"
.Cells(2, 7).Value = "CRF - 02"

'branch
.Cells(2, 1).Style.font.n ame = "batang"
.Cells(2, 1).style.font.u nderline = False
MsgBox("branch underline")
.Cells(2, 1).style.font.b old = True
MsgBox("branch bold")
.Cells(2, 1).Style.font.s ize = 11
.Cells(2, 1).Value = ds.Tables("form 1").Rows(ctr).I tem("branch")

' form title
.Cells(3, 3).Style.font.u nderline = True
.Cells(3, 3).Style.font.s ize = 11
.Cells(3, 3).Value = "CONTRACT REVIEW CUM BDI FORM"

'se code
.Cells(6, 7).Style.font.s ize = 9
.Cells(6, 7).Style.font.b old = True
.Cells(6, 7).Value = "SE Code"
.Cells(6, 8).Style.font.s ize = 11
.Cells(6, 8).Value = ds.Tables("form 1").Rows(ctr).I tem("sec")

'equipment type
.Cells(6, 2).Style.font.s ize = 11
.Cells(6, 2).Font.ColorIn dex = 15
.Cells(6, 2).Font.Name = "Arial black"
.Cells(6, 2).Value = equip
.Cells(6, 1).Value = "Equip"

--
Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...b-net/200604/1
Apr 17 '06 #1
5 3041
If you have Excel and want to know how something is done, then Open Excel,
create a new worksheet, go Tools > Macro > Record new macro. Record it in
the workbook so you can just get rid of it when done testing. Now what ever
you want to know, just do that manually such as selecting a cell and setting
it's font to bold, etc. When done, stop the recording and open the Visual
Basic Editor under that same menu and open the procedure that was just
created by the macro recording and see how it's being done.

"mrid via DotNetMonster.c om" <u16975@uwe> wrote in message
news:5ee7a69c9c 6e9@uwe...
hi. im exporting data from a vb form to excel. i am able to create a new
excel file, save and edit it without any trouble, but the formatting is
giving me hell! i need to be able to show certain cells in bold, with
underlining etc. i dont understand how, but in the following code, the
instruction for bold gets picked up for all the cells (even when i specify
font.bold = false), and the underlining is haphazardly used. the font
colour
formatting is also not getting picked up...
can someone please tell me how this thing works and what i should do?
With xlsheet
.Range("B1", "I50").RowHeigh t = 15
.Range("a1", "i50").ColumnWi dth = 8.43

'title of sheet
.Cells(1, 1).Font.ColorIn dex = 32
.Cells(1, 1).Style.font.s ize = 14
.Cells(1, 1).Font.Name = "Arial Black"
.Cells(1, 1).Value = "CONSUL"

'ISO form code
.Cells(2, 7).Font.ColorIn dex = 1
.Cells(2, 7).Style.font.s ize = 10
MsgBox("ISO CODE")
.Cells(2, 7).Style.font.b old = True
.Cells(2, 7).style.font.u nderline = False
.Cells(2, 7).Font.Name = "Batang"
.Cells(2, 7).Value = "CRF - 02"

'branch
.Cells(2, 1).Style.font.n ame = "batang"
.Cells(2, 1).style.font.u nderline = False
MsgBox("branch underline")
.Cells(2, 1).style.font.b old = True
MsgBox("branch bold")
.Cells(2, 1).Style.font.s ize = 11
.Cells(2, 1).Value =
ds.Tables("form 1").Rows(ctr).I tem("branch")

' form title
.Cells(3, 3).Style.font.u nderline = True
.Cells(3, 3).Style.font.s ize = 11
.Cells(3, 3).Value = "CONTRACT REVIEW CUM BDI FORM"

'se code
.Cells(6, 7).Style.font.s ize = 9
.Cells(6, 7).Style.font.b old = True
.Cells(6, 7).Value = "SE Code"
.Cells(6, 8).Style.font.s ize = 11
.Cells(6, 8).Value = ds.Tables("form 1").Rows(ctr).I tem("sec")

'equipment type
.Cells(6, 2).Style.font.s ize = 11
.Cells(6, 2).Font.ColorIn dex = 15
.Cells(6, 2).Font.Name = "Arial black"
.Cells(6, 2).Value = equip
.Cells(6, 1).Value = "Equip"

--
Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...b-net/200604/1

Apr 18 '06 #2
hi.

thanks for replying. i tried what you suggested, but am encountering a build
error when i try to use the macros code. eg. i get a
"system.data.ra nge" is not accessible in this context because it is "private".
not very sure what that means! also, for some reason the border setting seems
to throw an error everytime! - even the macros code when pasted in the vb pgm
gets squiggly green lines.

could you please tell me if theres any other way to format those cells?
getting totally frustrated!
+Vice wrote:
If you have Excel and want to know how something is done, then Open Excel,
create a new worksheet, go Tools > Macro > Record new macro. Record it in
the workbook so you can just get rid of it when done testing. Now what ever
you want to know, just do that manually such as selecting a cell and setting
it's font to bold, etc. When done, stop the recording and open the Visual
Basic Editor under that same menu and open the procedure that was just
created by the macro recording and see how it's being done.


--
it's all latin & geek to me! ;-)

Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...b-net/200604/1
Apr 18 '06 #3
Hello, mrid,

I think that your problem is that you are changing the properties of the
"Style" that is applied to the cells. This will change the attribute
for all cells to which that style has been applied. (Unless you have
done something to change it outside of the code snippit shown, this is
probably the "Normal" style that you are changing, so it will affect all
cells.)

Just remove the ".Style" property everywhere in your code snippit, and I
think you will get what you want.

Cheers,
Randy
mrid via DotNetMonster.c om wrote:
hi. im exporting data from a vb form to excel. i am able to create a new
excel file, save and edit it without any trouble, but the formatting is
giving me hell! i need to be able to show certain cells in bold, with
underlining etc. i dont understand how, but in the following code, the
instruction for bold gets picked up for all the cells (even when i specify
font.bold = false), and the underlining is haphazardly used. the font colour
formatting is also not getting picked up...
can someone please tell me how this thing works and what i should do?
With xlsheet
.Range("B1", "I50").RowHeigh t = 15
.Range("a1", "i50").ColumnWi dth = 8.43

'title of sheet
.Cells(1, 1).Font.ColorIn dex = 32
.Cells(1, 1).Style.font.s ize = 14
.Cells(1, 1).Font.Name = "Arial Black"
.Cells(1, 1).Value = "CONSUL"

'ISO form code
.Cells(2, 7).Font.ColorIn dex = 1
.Cells(2, 7).Style.font.s ize = 10
MsgBox("ISO CODE")
.Cells(2, 7).Style.font.b old = True
.Cells(2, 7).style.font.u nderline = False
.Cells(2, 7).Font.Name = "Batang"
.Cells(2, 7).Value = "CRF - 02"

'branch
.Cells(2, 1).Style.font.n ame = "batang"
.Cells(2, 1).style.font.u nderline = False
MsgBox("branch underline")
.Cells(2, 1).style.font.b old = True
MsgBox("branch bold")
.Cells(2, 1).Style.font.s ize = 11
.Cells(2, 1).Value = ds.Tables("form 1").Rows(ctr).I tem("branch")

' form title
.Cells(3, 3).Style.font.u nderline = True
.Cells(3, 3).Style.font.s ize = 11
.Cells(3, 3).Value = "CONTRACT REVIEW CUM BDI FORM"

'se code
.Cells(6, 7).Style.font.s ize = 9
.Cells(6, 7).Style.font.b old = True
.Cells(6, 7).Value = "SE Code"
.Cells(6, 8).Style.font.s ize = 11
.Cells(6, 8).Value = ds.Tables("form 1").Rows(ctr).I tem("sec")

'equipment type
.Cells(6, 2).Style.font.s ize = 11
.Cells(6, 2).Font.ColorIn dex = 15
.Cells(6, 2).Font.Name = "Arial black"
.Cells(6, 2).Value = equip
.Cells(6, 1).Value = "Equip"

Apr 18 '06 #4
Give us some samples of the macros code you've created.

"latin & geek via DotNetMonster.c om" <u16975@uwe> wrote in message
news:5ef2886ff9 713@uwe...
hi.

thanks for replying. i tried what you suggested, but am encountering a
build
error when i try to use the macros code. eg. i get a
"system.data.ra nge" is not accessible in this context because it is
"private".
not very sure what that means! also, for some reason the border setting
seems
to throw an error everytime! - even the macros code when pasted in the vb
pgm
gets squiggly green lines.

could you please tell me if theres any other way to format those cells?
getting totally frustrated!
+Vice wrote:
If you have Excel and want to know how something is done, then Open Excel,
create a new worksheet, go Tools > Macro > Record new macro. Record it in
the workbook so you can just get rid of it when done testing. Now what
ever
you want to know, just do that manually such as selecting a cell and
setting
it's font to bold, etc. When done, stop the recording and open the Visual
Basic Editor under that same menu and open the procedure that was just
created by the macro recording and see how it's being done.


--
it's all latin & geek to me! ;-)

Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...b-net/200604/1

Apr 19 '06 #5
Vice: thank you for responding, problem resolved now.
Randy you were absolutely right! Thanks a million - that was a life saver! :)
R. MacDonald wrote:
Hello, mrid,

I think that your problem is that you are changing the properties of the
"Style" that is applied to the cells. This will change the attribute
for all cells to which that style has been applied. (Unless you have
done something to change it outside of the code snippit shown, this is
probably the "Normal" style that you are changing, so it will affect all
cells.)

Just remove the ".Style" property everywhere in your code snippit, and I
think you will get what you want.

Cheers,
Randy
hi. im exporting data from a vb form to excel. i am able to create a new
excel file, save and edit it without any trouble, but the formatting is

[quoted text clipped - 51 lines]
.Cells(6, 2).Value = equip
.Cells(6, 1).Value = "Equip"


--
it's all latin & geek to me! ;-)

Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...b-net/200604/1
Apr 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2942
by: ImraneA | last post by:
Hi there Have a database, where front-end interface allows user to select a ms access database. From there, standard tables are linked. Routine, that creates a spreadsheet, for each table a separate sheet within spreadsheet is created. Particular fields are selected. User requires fields to be auto-fitted. Problem, is that some tables have more than 1200> rows. Code generates error message. Is there a way of getting around this...
3
6222
by: washoetech | last post by:
I have a gridview control. In this grid view there is a column for the price of an item. Some of the prices have a dollar sign in front of it and some dont. How do I get rid of the dollar sign if it is in front of the value? My guess would be to use a template column but I dont know how to go about this. Any ideas? Below is an example of what the data looks like raw from the database: $456.95 200.89
10
3164
by: Coleen | last post by:
Hi all :-) I have a weird formatting problem with an HTML table that I am populating using VB.Net and HTML. Here is the snippet of code for the cell I'm trying to format: Dim ld_tot_pet_clean_fee_calc As Double ld_tot_pet_clean_fee_calc = li_net_total_calc * 0.0075 ld_tot_pet_clean_fee = lo_misc_func.FormatMC(ld_tot_pet_clean_fee_calc, "D") Session("tot_pet_clean_fee") = lo_misc_func.FormatMC(ld_tot_pet_clean_fee, "D")...
1
4578
by: euan | last post by:
HI Guys, I have bee using conditional formatting in the datagrid recently and I am moving over to framework 2.0 and noticed the datagrid has been replaced by the gridview. So, I would like to do conditional formatting on the gridview but it doesnt have the same methods. Currently in my datagrid I have this (this is just hacked together randomly but gives you the idea):
2
7344
by: jacqueharper | last post by:
I need to change the formatting of individual cells in a datagrid. I cannot figure out how to address individual cells by their column name. I have a DataTable which contains (for instance) columns called Weight, Length and Diameter. The table is bound to a DataGrid, and I am using the ItemDataBound behavior to execute code that checks values in the table, e.g.: public void OnDataBindValuesCheck (object sender, DataGridItemEventArgs e)
13
2553
by: Niyazi | last post by:
Hi I have a report that I have to run it monthly in my machine. My code in VB.NET and I access AS400 to get data, anaysie it and send into pre formated Excel sheet. The data consist of 9000 rows. I use data table and with for loop I send the data row by row in pre-formated Excel sheet. My machine is:
4
8336
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the date column always shows the date and time while I just want the short date. I have tried applying a format string {0:d} but to no avail. I saw a lot of posts regarding the htmlencode property but I do not know how to turn that off for a...
1
1740
by: nickb34 | last post by:
I don't have much experience with VB and I have found Excel's conditional formatting very limited. I need a macro that will search through all the cells and when it finds a blank cell, it needs to be filled with white. The limitations of the conditional formatting are causing all of the cells to be filled with color because it sees the number 0 as being blank. I need 0 to be shaded green (as well as other conditions having other colors), but any...
10
9698
by: afromanam | last post by:
Regards, Please help What I'm trying to do is this: (and I can't use reports since I must export to Excel) I export some queries to different tabs in an excel workbook I then loop through each tab and apply autowidth to columns and apply autofilter to the first row of every tab in the workbook. I've this down
0
10438
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.