![]() |
Simple column moving code needed
Hi there,
Please help a Newb! :) I have to do the following in code: There are 5 columns. Column with range A1:A6 must go to the back, i.e. to F1:F6 Each of the columns must then move one to the left. Simple, but how? Thanks in advance! |
Simple column moving code needed
Hi Jean,
Try: Sub Tester1() With Range("A1:A6") .Cut Range("G1") .Delete Shift:=xlToLeft End With End Sub If you are new to macros, you may wish to visit David McRitchie's Introduction to Macros and User Defined Functions page at:: http://www.mvps.org/dmcritchie/excel/getstarted.htm --- Regards, Norman "Jean" wrote in message ups.com... Hi there, Please help a Newb! :) I have to do the following in code: There are 5 columns. Column with range A1:A6 must go to the back, i.e. to F1:F6 Each of the columns must then move one to the left. Simple, but how? Thanks in advance! |
Simple column moving code needed
If you just want to move your selection A1 to A6 to the last availabl column Sub Moving_Cols() Range("A1:A6").Cut Range("IV1").End(xlToLeft).Offset(0, 1).Select ActiveSheet.Paste Application.CutCopyMode = False End Su -- bhawanePosted from http://www.pcreview.co.uk/ newsgroup acces |
Simple column moving code needed
Hi Jean,
Apologies, I assumed 6 columns, not 5 as you stipulate. Try, therefo Sub Tester1() Range("A1:A6").Cut Range("F1") Range("A1:A6").Delete Shift:=xlToLeft End Sub --- Regards, Norman "Norman Jones" wrote in message ... Hi Jean, Try: Sub Tester1() With Range("A1:A6") .Cut Range("G1") .Delete Shift:=xlToLeft End With End Sub If you are new to macros, you may wish to visit David McRitchie's Introduction to Macros and User Defined Functions page at:: http://www.mvps.org/dmcritchie/excel/getstarted.htm --- Regards, Norman "Jean" wrote in message ups.com... Hi there, Please help a Newb! :) I have to do the following in code: There are 5 columns. Column with range A1:A6 must go to the back, i.e. to F1:F6 Each of the columns must then move one to the left. Simple, but how? Thanks in advance! |
Simple column moving code needed
hi guys
I am actually automating an Excel object from Access. What I did was look at http://www.mvps.org/dmcritchie*/excel/getstarted.htm and then create a macro with the following code inside: .Range("B1:B6").Select Selection.Cut Destination:=Range("G1:G6") .Range("C1:G6").Select Selection.Cut Destination:=Range("B1:F6") .Range("A7").Select however, when I add this code to my Access code module, strange things happen. I run the code once, and the Excel.exe process in the Task Manager stays there! It should be killed, according to the last line in my code. This was not happening before I added this simple column-moving-code. Norman, I tried adding your code example too, but the same happens. Function CreateChart(strSourceName As String, _ strFileName As String) Dim xlApp As Excel.Application Dim xlWrkbk As Excel.Workbook Dim xlChartObj As Excel.Chart Dim xlSourceRange As Excel.Range Dim xlColPoint As Excel.Point Dim CurCell As Object On Error GoTo Err_CreateChart ' Create an Excel workbook file based on the ' object specified in the second argument. DoCmd.TransferSpreadsheet acExport, , _ strSourceName, strFileName, False ' Create a Microsoft Excel object. Set xlApp = CreateObject("Excel.Application") ' Open the spreadsheet to which you exported the data. Set xlWrkbk = xlApp.Workbooks.Open(strFileName) ' Add "Summe" row manually With xlWrkbk.Worksheets(1) .Range("a6") = "Summe" .Range("b6").Formula = "=sum(B2:B5)" .Range("b6:f6").FillRight ' My macro code is HERE '-------------------------------------- .Range("B1:B6").Select Selection.Cut Destination:=Range("G1:G6") .Range("C1:G6").Select Selection.Cut Destination:=Range("B1:F6") .Range("A7").Select '--------------------------------- End With '#1 ' Determine the size of the range and store it. Set xlSourceRange = _ xlWrkbk.Worksheets(1).Range("a1").CurrentRegion ' Create a new chart. Set xlChartObj = xlApp.Charts.Add ' Format the chart. With xlChartObj ' Specify chart type as 3D. .ChartType = xlColumnClustered ' Set the range of the chart. .SetSourceData Source:=xlSourceRange, _ PlotBy:=xlRows ' Specify that the chart is located on a new sheet. .Location Whe=xlLocationAsNewSheet ' Create and set the title; set title font. .HasTitle = True With .ChartTitle .Characters.Text = _ "Aufteilung der Problempunkte nach Fachprozessen(Module)" .Font.Size = 14 End With 'Position the chart legend at the bottom and increase width With .Legend .Position = xlLegendPositionBottom .Width = 700 End With 'Y-Axis description With .Axes(xlValue) .HasTitle = True .AxisTitle.Caption = "Anzahl Problempunkte" End With 'apply white background .PlotArea.Interior.ColorIndex = 2 ' Series: Freigabe abgeschlossen With .SeriesCollection(1) .ApplyDataLabels Type:=xlDataLabelsShowValue .PlotOrder = 3 .Interior.Color = RGB(255, 255, 0) '.DataLabels.NumberFormat = "$#,##0" End With ' Series: Handshake With .SeriesCollection(1) .ApplyDataLabels Type:=xlDataLabelsShowValue .PlotOrder = 1 .Interior.Color = RGB(0, 0, 0) End With ' Series: In Bearbeitung With .SeriesCollection(2) .ApplyDataLabels Type:=xlDataLabelsShowValue .PlotOrder = 2 .Interior.Color = RGB(255, 0, 0) End With ' Series: Maßnahme umgesetzt With .SeriesCollection(4) .ApplyDataLabels Type:=xlDataLabelsShowValue .PlotOrder = 4 .Interior.Color = RGB(0, 255, 0) End With ' Series: Summe With .SeriesCollection(5) .ApplyDataLabels Type:=xlDataLabelsShowValue .PlotOrder = 5 .Interior.Color = RGB(204, 204, 204) End With End With ' Position the points further from the tops ' of the columns. 'For Each xlColPoint In _ xlChartObj.SeriesCollection(1).Points 'xlColPoint.DataLabel.Top = _ xlColPoint.DataLabel.Top - 11 'Next xlColPoint ' Save and close the workbook ' and quit Microsoft Excel. With xlWrkbk .Save .Close End With xlApp.Quit Exit_CreateChart: Set xlSourceRange = Nothing Set xlColPoint = Nothing Set xlChartObj = Nothing Set xlWrkbk = Nothing Set xlApp = Nothing Exit Function Err_CreateChart: MsgBox CStr(Err) & " " & Err.Description Resume Exit_CreateChart End Function |
All times are GMT +1. The time now is 07:27 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com