ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel and Vba questions (https://www.excelbanter.com/excel-programming/342576-excel-vba-questions.html)

NewGuy100[_6_]

Excel and Vba questions
 

I have a couple of questions regarding macros and excel.

1. I have a vba function that prints data to a text file. It's in
columns. How do I align all the data into the correct column. I'
guessing I have to right justify this,but i don't know how. Can someon
help me with this?

2. When I create a chart using vba, it keeps adding new charts when
run the program. How do i make it overwrite the current chart

--
NewGuy10
-----------------------------------------------------------------------
NewGuy100's Profile: http://www.excelforum.com/member.php...fo&userid=2793
View this thread: http://www.excelforum.com/showthread.php?threadid=47545


Dave Peterson

Excel and Vba questions
 
#1:
http://google.com/groups?threadm=015...0a% 40phx.gbl

#2: How about just deleting the existing chart before your code adds the new
one?

NewGuy100 wrote:

I have a couple of questions regarding macros and excel.

1. I have a vba function that prints data to a text file. It's in 6
columns. How do I align all the data into the correct column. I'm
guessing I have to right justify this,but i don't know how. Can someone
help me with this?

2. When I create a chart using vba, it keeps adding new charts when i
run the program. How do i make it overwrite the current chart?

--
NewGuy100
------------------------------------------------------------------------
NewGuy100's Profile: http://www.excelforum.com/member.php...o&userid=27935
View this thread: http://www.excelforum.com/showthread...hreadid=475455


--

Dave Peterson

Jim Rech

Excel and Vba questions
 
RE #1 I assume you know the width of each column so you have to add leading
spaces before each item to make its length equal to the current column's
width. You might find that using the RSet statement makes this a little
simpler.

--
Jim
"NewGuy100" wrote
in message ...
|
| I have a couple of questions regarding macros and excel.
|
| 1. I have a vba function that prints data to a text file. It's in 6
| columns. How do I align all the data into the correct column. I'm
| guessing I have to right justify this,but i don't know how. Can someone
| help me with this?
|
| 2. When I create a chart using vba, it keeps adding new charts when i
| run the program. How do i make it overwrite the current chart?
|
|
| --
| NewGuy100
| ------------------------------------------------------------------------
| NewGuy100's Profile:
http://www.excelforum.com/member.php...o&userid=27935
| View this thread: http://www.excelforum.com/showthread...hreadid=475455
|



K Dales[_2_]

Excel and Vba questions
 
1. Let's say you need to take the values in the range A1:F5 and convert to
text with each column filling 10 spaces (right justified).
Dim LineOfData As String
For i = 1 to 5 ' for the rows
LineOfData = "" ' build new string for each line
For j = 1 to 6 ' for the columns
LineOfData = LineOfData & Right(Space(10) &
Worksheet("SheetName").Cells(i,j).Text,10) ' Spaces to pad, Right function
ensures result is 10 characters long
Next j
' Write the line of data to your file here
Next i

2. You must be doing a Charts.Add (or ChartObjects.Add) and, naturally, this
will add a chart each time it is run. Perhaps the easiest thing to do given
your situation now would be to add a line to delete the existing chart, e.g.
ThisWorkbook.Charts(1).Delete (for a chart sheet) or
ActiveSheet.ChartObjects(1).Delete (for an embedded chart), and then to build
the new one. It would be cleaner to have created the initial chart as part
of your workbook design and then used your code just to change the parts that
need updating each time it is run, but by now that would mean reworking a lot
of your code.
--
- K Dales


"NewGuy100" wrote:


I have a couple of questions regarding macros and excel.

1. I have a vba function that prints data to a text file. It's in 6
columns. How do I align all the data into the correct column. I'm
guessing I have to right justify this,but i don't know how. Can someone
help me with this?

2. When I create a chart using vba, it keeps adding new charts when i
run the program. How do i make it overwrite the current chart?


--
NewGuy100
------------------------------------------------------------------------
NewGuy100's Profile: http://www.excelforum.com/member.php...o&userid=27935
View this thread: http://www.excelforum.com/showthread...hreadid=475455



NewGuy100[_7_]

Excel and Vba questions
 

Is there a function to check if a chart exists

--
NewGuy10
-----------------------------------------------------------------------
NewGuy100's Profile: http://www.excelforum.com/member.php...fo&userid=2793
View this thread: http://www.excelforum.com/showthread.php?threadid=47545



All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com