Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 65
Default Minimizing number of commands

Hello Happy Thursday!! to everyone.
Any help is deeply appreciated. I got two questions:

1) I have pasted part of my code below:

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If

Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash


Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End Sub


The problem is I actually have 60 heading commands, 60 If statemets etc. on
the code
How can I write this code in a more compact way??

2) My other question: When I execute the above macro, it generates me a
table with the corresponding headings and a given value under those headings:
EXAMPLE

HEADING1='title1.' HEADING2= 55. HEADING3=46. /

HEADING4='title2.' HEADING5=66. HEADING2=56. /

etc............
etc............
etc............

I want it to display it as is with the only exception that when the user
types in a value in Sheet 1 under a given heading, if this particular value
has a decimal in it such as 2.33 then I want to display it in Sheet
("Output") as 2.33 and not 2.33. ( with only the first decimal and not the
second) But if the user types in a value under a heading without a decimal
then I would like to display it in Sheet("Output") as it is right now with a
decimal at the end.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
minimizing space between cell content for printing me Excel Worksheet Functions 0 August 2nd 06 11:40 PM
Minimizing excel window grays it out on taskbar Sysop Excel Discussion (Misc queries) 0 December 5th 05 07:00 PM
minimizing problem Dave Excel Discussion (Misc queries) 5 June 7th 05 07:29 PM
NUMBER OF COMMANDS RAJEEV CHADHA Excel Worksheet Functions 4 April 20th 05 07:06 PM
putting a number equal to writing commands martin Excel Worksheet Functions 7 March 14th 05 03:22 PM


All times are GMT +1. The time now is 07:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"