|
 |
access thread: Copying a column to the last column in a spreadsheet
Message #1 by "Bryan" <kushwood@e...> on Fri, 14 Mar 2003 22:51:03
|
|
I would like to copy a column (let's say column B) and paste it to the
last column of the worksheet. What would be the code for that?
Also, in the following how can I increment column headings:
Dim CellData As String
Dim num As Integer
num = 1
CellData = xlApp.ActiveSheet.Cells(2, 1).Value
Do Until CellData = ""
xlApp.Worksheets(1).Columns("B:I").ColumnWidth = 8
xlApp.Worksheets(1).Cells(1, num).HorizontalAlignment = xlCenter
xlApp.Worksheets(1).Cells(1, num).Borders.LineStyle = xlDouble
CellData = xlApp.Worksheets(1).Cells(2, num).Value
num = num + 1
Loop
The Line: xlApp.Worksheets(1).Columns("B:I").ColumnWidth = 8
I would like to increment the "B:I" code... like aplha+1... but that won't
work since columns are letters. Any suggestions?
Message #2 by "Tech_Mark" <tek_mark@h...> on Sat, 15 Mar 2003 12:37:34 -0500
|
|
Bryan, an easy way to code this (AND almost anything else you can think of)
is to go in to Excel and use Excel's record feature. (In the Tools menu
pulldown.) Just make sure to save the macros in the current sheet, since
they will be throw-aways.
To get to the macros once you've recorded them, press alt-F11.
Don't be overly concerned by any errors you make in recording the macro,
when you review the code, you will only be concerned with the command
structure and you will be able to tweak it by hand. Fix up the code to do
what you want, and test it in Excel. Then (and here's a part I've not done
before--) copy the selected code segment you want and paste it into your
Access VBA program, probably sandwiched with
With xlApp.Worksheets(1)
...
End With
Mark
----- Original Message -----
From: "Bryan" <kushwood@e...>
To: "Access" <access@p...>
Sent: Friday, March 14, 2003 10:51 PM
Subject: [access] Copying a column to the last column in a spreadsheet
> I would like to copy a column (let's say column B) and paste it to the
> last column of the worksheet. What would be the code for that?
>
> Also, in the following how can I increment column headings:
> Dim CellData As String
> Dim num As Integer
> num = 1
> CellData = xlApp.ActiveSheet.Cells(2, 1).Value
>
> Do Until CellData = ""
> xlApp.Worksheets(1).Columns("B:I").ColumnWidth = 8
> xlApp.Worksheets(1).Cells(1, num).HorizontalAlignment = xlCenter
> xlApp.Worksheets(1).Cells(1, num).Borders.LineStyle = xlDouble
> CellData = xlApp.Worksheets(1).Cells(2, num).Value
> num = num + 1
> Loop
>
> The Line: xlApp.Worksheets(1).Columns("B:I").ColumnWidth = 8
> I would like to increment the "B:I" code... like aplha+1... but that won't
> work since columns are letters. Any suggestions?
Message #3 by "Bryan" <kushwood@e...> on Sat, 15 Mar 2003 18:59:36
|
|
Thanks, for the reply... but Excel returns a Column settings... it already
knows what the column is... for example Columns("F:F"). Instead of having
the F:F, I need some kind of method that returns the the current column
letter. How would I do that?
> Bryan, an easy way to code this (AND almost anything else you can think
of)
is to go in to Excel and use Excel's record feature. (In the Tools menu
pulldown.) Just make sure to save the macros in the current sheet, since
they will be throw-aways.
To get to the macros once you've recorded them, press alt-F11.
Don't be overly concerned by any errors you make in recording the macro,
when you review the code, you will only be concerned with the command
structure and you will be able to tweak it by hand. Fix up the code to do
what you want, and test it in Excel. Then (and here's a part I've not done
before--) copy the selected code segment you want and paste it into your
Access VBA program, probably sandwiched with
With xlApp.Worksheets(1)
...
End With
Mark
----- Original Message -----
From: "Bryan" <kushwood@e...>
To: "Access" <access@p...>
Sent: Friday, March 14, 2003 10:51 PM
Subject: [access] Copying a column to the last column in a spreadsheet
> I would like to copy a column (let's say column B) and paste it to the
> last column of the worksheet. What would be the code for that?
>
> Also, in the following how can I increment column headings:
> Dim CellData As String
> Dim num As Integer
> num = 1
> CellData = xlApp.ActiveSheet.Cells(2, 1).Value
>
> Do Until CellData = ""
> xlApp.Worksheets(1).Columns("B:I").ColumnWidth = 8
> xlApp.Worksheets(1).Cells(1, num).HorizontalAlignment = xlCenter
> xlApp.Worksheets(1).Cells(1, num).Borders.LineStyle = xlDouble
> CellData = xlApp.Worksheets(1).Cells(2, num).Value
> num = num + 1
> Loop
>
> The Line: xlApp.Worksheets(1).Columns("B:I").ColumnWidth = 8
> I would like to increment the "B:I" code... like aplha+1... but that
won't
> work since columns are letters. Any suggestions?
Message #4 by "Tech_Mark" <tek_mark@h...> on Sun, 16 Mar 2003 11:52:37 -0500
|
|
Bryan,
In Excel, you can do a
Selection.End(xlToRight).Select
This will put you at the last currently used column. I can't remember the
command to get this column name, and I have to leave right now, but it might
be something like v=cstr(column); then add 1 to the column. It will take a
little research.
Perhaps more later.
Mark
----- Original Message -----
From: "Bryan" <kushwood@e...>
To: "Access" <access@p...>
Sent: Saturday, March 15, 2003 6:59 PM
Subject: [access] Re: Copying a column to the last column in a spreadsheet
> Thanks, for the reply... but Excel returns a Column settings... it already
> knows what the column is... for example Columns("F:F"). Instead of having
> the F:F, I need some kind of method that returns the the current column
> letter. How would I do that?
>
>
|
|
 |