Copy Paste With Macros - Variable Positioning

Jul 12, 2007

Using a macro, how do I tell Excel to:

1. Copy the xth row and paste it before the yth row

2. Copy the mth column and paste it before the nth column

3. Copy the cell a,b and paste it in he position c,d
where x,y,m,n,a,b,c,d are variables, the value of which the user inputs, say in cells A1, A2, A3, A4, A5, A6, A7 and A8 respectively.

In other words, I need to read numbers m and n which are the values of cells A1 and A2, then I need to go to column number m (for instance, if m=4, I go to column D), copy the whole row, go to column number n (for instance, if m=6, I go to column F), and insert the copied column.

Also wondering if VBA provides any way to quickly horizontally and vertially flip copied tables while pasting. While I am aware of the transpose function which swaps rows with columns, I am looking for a way to reverse the order of either the rows or the columns as per my need, without having to copy-paste row-by-row or column-by-column.

View 9 Replies


ADVERTISEMENT

Insert A Variable Number Of Rows And Copy And Paste From And To Variable Positions

Aug 8, 2009

On the attached Excel file, I have code that will insert a variable number of rows and copy and paste from and to variable positions. That all works fine when run from a command button, but when I try to run it from the Worksheet_Calculate by entering 1 in J1 or K1 (inrange cell is J1+K1 for testing purposes) the CommandButton1_Click sub runs continously until an error occurs.

View 4 Replies View Related

Copy/paste Macros Will Not Copy Filtered Items

Sep 25, 2009

The following sub will look in the file ("FY09 SOF"), in column "A", search for the strings that begin with "2109", "3009", or ends in "-1", and copy the entire row. It will then paste these in the file ("FY09 PR Log Blank").

I have found that in the file ("FY09 SOF"), if things are filtered in any row, it will not copy those necessary items.

The data filter is on row 13 of each sheet. Is there a way of fixing this? (i.e. having the macros select "all" on the filter before copying the sheet? There are 60 sheets so a macros will be necessary.

Sub get_data()
Dim wb As Workbook, wbDest As Workbook
Dim ws As Worksheet, wsDest As Worksheet
Dim lngCalc As Long
Dim FoundCells As Range
Dim FoundCell As Range

Set wb = Workbooks("FY09 SOF")
Set wbDest = Workbooks("FY09 PR Log Blank")
Set wsDest = wbDest.Worksheets("Paste all here, then sort")

With Application
.ScreenUpdating = False
lngCalc = .Calculation
.Calculation = xlCalculationManual
End With
For Each ws In wb.Worksheets.............................

View 9 Replies View Related

Macros - Copy And Paste

May 26, 2008

I am trying to create a macro that will take data inputed into a set range in sheet one and go to the appropriate sheet to paste in the data as a value in the right spot. The range on sheet one is A2:I2. The data in cell reference D2 in that range will be the same as the name of the sheet to go to where i want to paste the information as a value.

Then the data in cell reference E2 in that range will be a date, the macro will need to find that date on the sheet it has gone to and paste in the information in the row below it, first inserting a blank row to ensure that any data that has already been inputed is not pasted over but shifted down one row to ensure no data is lost. Then i will require the same information to be pasted into the last 2 sheets simply added a row and inserting the data before returning to sheet 1 and deleting the data entered ready for the next entry to be made.

The process should take information entered in Sheet 1, in this case to make a reservation on a trip, paste it into the relevant trip sheet (D2 cell reference will be a trip code) under the relevant trip date (E2 cell reference will be the date). Then also paste a copy on the second last sheet which will be the Invoice sheet and the last sheet which will be a sales tracking sheet.

View 9 Replies View Related

Copy AND Paste Macros

Sep 16, 2009

I'm desperate for a copy paste macros that will:

1) Copy H3:H143 (141 rows) from "Sheet 1" and place this on "Sheet 2" on D4:D144 (141 rows)

2) Copy I:3:I143 (141 rows) from "Sheet 1" and place this on "Sheet 2" on I4:I144 (141 rows)

So, in essence, it will copy every single column across on "Sheet 1", but will paste every 5 columns on "Sheet 2" .

I then need this to loop 33 times to continually copy and paste across columns.

View 9 Replies View Related

Disable Cut / Copy And Paste Using Macros

Jun 27, 2014

I want to disable cut,copy,paste functionality (shortcut keys also) from excel.

View 1 Replies View Related

Macros That Copy And Paste Certain Range

Aug 18, 2009

I need a macros that can start of with this:

Sheet1

DEFGH50123DAMAGE6
ABCD7
ABCD8
ABCD9
ABC
10
ABC
11
AB
D12
ABCD13..........

View 9 Replies View Related

Copy / Paste With Variable Rows

Mar 16, 2012

I have some code that uses a form so you can choose the folder that contains all the spreadsheets that I need to copy. My issue is I have about 20 spreadsheets, some have the tab labled M3 and others Sheet1. Next is each spreadsheet has a different amount of rows in them. My data will always start in cells B4:N4 but may 20, 100, 1000 rows long.

My code works but only copies the first four rows of the last sheet open.

Code:

Private Sub cmdbtnProcess_Click()
Check_Path
End Sub
Sub Check_Path()
If txtboxPath.Value = Empty Or txtboxFile.Value = Empty Then

[Code]...

View 2 Replies View Related

Macro To Copy & Paste Variable Range

Aug 15, 2007

I am trying to write a very basic macro to copy and paste, but when I record the keystrokes, step 4 (see below) seems to be recording absolute cells and not relative (?). At any rate, I can't seem to figure out how to get it to select the text the way I want it to. These are the keystrokes I want:

1. Ctrl-c in the current cell <copy the current cell>

2. DownArrow <move down one cell>

3. Shift(hold)-End-Down <select the blank spaces from here down until the next occupied
cell>

4. Shift(hold)-Up <move the selection up one from the bottom to exclude the occupied cell>

5. Ctrl-v <paste>

6. End-Down <move down to the last occupied cell>

I have set the record tool to record "relative" references.

Below is the code that was recorded. It's line 5 that's not working - how do I fix it? What is the command to tell the program to press the shift key and an up arrow?? Such a simple thing, and yet I can't find the answer anywhere! Things sure have gotten complicated since the old Lotus 1-2-3 macro language...

Sub Fill()
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Range("A1:A17").Select
ActiveSheet.Paste
Selection.End(xlDown).Select
End Sub

View 8 Replies View Related

Macro To Copy And Paste Into Another Sheet At Variable Rows?

Nov 14, 2012

Sheet 2 has 3 cells with values:

C14, C15, C16

I need VB code to:

copy the values in those cells

Return to Sheet 1, let the user click a cell in any row in Colum F, then Paste them (Special, Values and Transpose)

View 4 Replies View Related

Copy And Paste Macro - Variable Number Of Rows

Jan 13, 2009

I am working on a macro where I am creating a formula to string together some text columns and then copy the formula down the entire column. The data source I will be performing this on will change in number of rows period to period. The data would be in columns A,B & C and the formula is in D. The formula in D is stringing together the data in AB & C and then I want to copy and paste that formula down to the bottom of all of the data. What would the code be for the copy and paste with variable rows?

View 9 Replies View Related

Copy Variable Sized Row And Paste Select Columns Into Different Worksheet

Sep 29, 2012

I'm in the middle of building a code that will look at the value in Sheet: "DATA" column "J", for each row that matches a criteria that I pull from a cell - Sheet: "Test" Cell: "C1".

The number of rows varies. I want to paste columns: "I2, K2:P2, U2:AJ2" when the value in Sheet: "DATA" column "J" matches the cell "C1".
I'm using a Command button to click every time I want to generate the filtered data. And I would prefer the code to always copy data starting at Sheet: "Test" Cell: "K2".

I've copied, below, my test code that I have so far which only copies row 2 from the Sheet: "Data", and copies it into Sheet: "Test", starting at K2.

VB:

Private Sub CommandButton2_Click()
If Sheets("DATA").Range("J2").Value = Sheets("Test").Cells(1, 3) Then
Sheets("DATA").Range("I2,K2:P2,U2:AJ2").Copy
Sheets("Test").Cells(2, 11).PasteSpecial Paste:=xlValues, Operation:=xlNone
End If
End Sub

View 3 Replies View Related

Two Macros - Object Variable Or With Block Variable Not Set Error

Jul 11, 2014

I have two macros that run fine separately. I want to join them, but when I do I get an Object variable or With block variable not set error.

Here's the code

Code:

Sub border_highlight_insert()
' Change heavy border to new column, change tint - keyed to year A6
With ActiveSheet
Dim i As Integer

[Code]....

View 2 Replies View Related

Copy And Paste Special Values But Getting Error 'Compile Error - Expected Function Or Variable'

Feb 7, 2007

I am trying to run create a simple macro that copies and paste special values - something I have done 100's of times but for some reason I keep getting an error message - even though I recorded the macro and didnt write it by hand - see below:

Sub Macro6()
Cells.Select
selection.Copy
selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

For which I get 'Compile Error - Expected Function or Variable'

View 6 Replies View Related

Copy A Range And Paste It Over A Variable Range

Jul 16, 2009

I am using the code below to copy a range and paste it over a variable range.

View 4 Replies View Related

Passing Variable To Two Macros?

Jul 25, 2012

I have the following code in 'ThisWorkbook':

VB:
Private Sub Workbook_Open()
Call Meetdata
End Sub

It calls this macro which is in a standard module:

VB:
Public firstvariablename As String
Public secondvariablename As String
Sub Meetdata()
regionname = InputBox("Enter the name of the Region.", "Region Name: North, South, East, West")
meetdate = InputBox("Enter the date of the Meet.", "Date of Meet")
End Sub

This set-up should make the variables available to all the other macros in the workbook. I have two other macros that need to use the values stored in these two variables that are entered into the two 'InputBox' statements. These two macros are in the same module and follow the 'Meetdata' sub. When I run the first macro, it recognizes the variables. When I run the second macro for some reason the variables are not recognized. To test the values returned by the variables, I placed the following code at the end of the first macro and again at the beginning of the second macro .

VB:
MsgBox(firstvariablename & " " & secondvariablename)

At the end of the first macro, the MsgBox returns the correct values stored in the variables which means that when the macro completes its run, the variables still hold their values. When I run the second macro with the MsgBox at the beginning, the Msgbox returns a blank. Somehow, the variables have been re-set to a null value. I can't figure out why the variables have been re-set to null. [URL]

View 2 Replies View Related

Copy, Paste, Change Font Size, Copy, Paste, Print VBA

Mar 29, 2009

I'm using 2003.

1. Copy cells B5 to V-First blank row in Strength Tests worksheet
2. Paste cells into Racks worksheet in cell C5
3. Change font size to 6
4. Sort by Column T descending then by Column C ascending
5. Copy one row (A5-W5 (1Rx23C)) from Racks worksheet
6. Paste row into M1 worksheet in cell D4
7. Print M1
8. Drop down one row on the Racks worksheet
9. Repeat steps 5-8 until there's a blank row.

View 9 Replies View Related

Variable Data With Excel Macros

Jul 13, 2012

I am relatively new to macros and trying to understand how to modify a certain macro that I recorded. Here is what I'm trying to do...every month I have a file with a bunch of data. I need to take that file, filter it, and pull certain data from it into separate tabs within the same workbook. The number of rows of data will change from month to month however I'd like to have a macro that will capture however many lines of data. I have several rows/columns of info I need to copy between tabs but I recorded a macro with just one filter and one row of data for now just to try and understand what I need to do. I have copied it below.

Sub Intersegment()
'
' Intersegment Macro
'
'
ActiveSheet.Range("$A$1:$AF$727").AutoFilter Field:=14, Criteria1:= _
"Intersegment"
ActiveWindow.ScrollColumn = 2

[Code] ........

View 4 Replies View Related

Pasting Variable In Filter In VBA Macros?

Sep 30, 2013

I am trying to write a macro where I have to select a name, copy it and search in a Pivot filter if a certain condition is met. I am stuck at a place where I am unable to paste the selected value as a variable.

Code:

For Each cell In .Range("I2:I" & .Range("I" & .Rows.Count).End(xlUp).Row)
If cell.Value = True Then
Range("G" & N).Select
Selection.Copy
Range("A3").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("QC POC").PivotFilters.Add _
Type:=xlCaptionContains, Value1:="selection.paste"

The portion which is in bold (Value1=) needs to contain my selection (which is actually a name)

View 8 Replies View Related

Pass Cell Variable Between Macros

Jun 11, 2007

I have a macro that nicely select the named range that the active cell is in. I want to chain on to that macro a macro that has a parameter a range with that active selection. I dont see how to "take" the active selection on the worksheet from within the macro and pass it to another. I assume I could change the cellInRange macro to return a range, however I dont yet see how to do that.

View 2 Replies View Related

Excel 2007 :: How To Pass Boolean Variable Between Two Macros

Feb 10, 2012

I am attempting to pass a boolean variable between two macros. The SUBMIT macro calls the STATUS macro to do some verifications and the STATUS macro should return the boolean variable RDY back to the SUBMIT macro, but does not.

I am using Excel 2007. Both macros are in the same Module. The STATUS macro is called from several places in the code.

Public Rdy As Boolean
Sub Submit()
[code]
Call Status
If Rdy=True then msgbox("You have completed your form") else msgbox ("Not ready")
[code]
end sub

[Code]....

View 1 Replies View Related

Macros To Cut A Row And Paste To Another Sheet

Aug 3, 2009

It's actually a two-parter. I have two buttons over each of five sections - CUT and PASTE. So each salesperson (section) has its own buttons.

I need to be able to click a CUT button and have the macro either COPY or CUT the row of data and then DELETE the row. Then I need to be able to choose another worksheet and click PASTE over a section within that worksheet and have the macro INSERT a blank line and then PASTE the row of data.

The attached worksheet shows four buttons for each salesperson. The other two buttons work great. I've tried several ways with no luck; and I believe this is the only way I can work off various worksheets.

View 11 Replies View Related

Macros & Formulas Paste Into A Worksheet

Aug 6, 2008

I have a formula which i need to paste into a worksheet, doing this is tedious and boring to say the least, problem is i am not sure how to get the macro to skip blank lines and only insert the formula where there are prices. Each week the worksheet changes so there is no consistent layout.

View 9 Replies View Related

Positioning A Picture

Jun 2, 2014

I've got the following code going :

[Code] .....

I can't get my With statement to work.

View 1 Replies View Related

List Box Positioning

Apr 10, 2009

I've got an Excel spreadsheet with quite a bit of code behind it (2007).
User can select a cell in Col A and push 'F2" and a ListBox pops up (becomes visible).
But if the User is on line 72 say, then the box is in the wrong position (and often becomes visible with diagonal lines across it!); that is I need to determine where the User is and set the ListBox position further down.

I tried to do this by calculating the offset based upon the row number they were on. This works really well, unless, the lines/records are varying heights.

Is there an easy way to do this ????? I have this feeling I must be missing something really simple about how this should work - I'm sure there must be a way that Excel has to handle this.

View 9 Replies View Related

Positioning Shape Objects In VBA

Aug 22, 2006

I am trying to work out how to pisition a new object in some VBA code, I can do this if I copy an object then click on a cell, e.g. H74 then paste, but the properties for an object want this in points.

ActiveSheet.Shapes.AddShape(msoShapeOval, 50, 50, 26.25, 26.25).Select

What I want to do is select the cell H74, then find the coordinates for that cell then use these when creating the shape, I appreciate these coordinates will need to be assigned to variables, but how do you get then from a given cell?

View 3 Replies View Related

Sizing And Positioning Of Shapes

Feb 14, 2007

I have a workbook where each name in a list has a picture of a flag of the country for that name. The flags are initially assigned to a cell with the country name (see sample attached). Later in the project the flag is copied to a cell in another sheet and assigned to the correct name in the list. The row heights in this list of names is larger than the row height of the sheet with list of countries.

The flags in the sample have been manually sized and positioned as accurately as possible. I am struggling with the VBA code to size and position each flag exactly so that there is a very small gap between the top, bottom and left of the flag and the cell border. Each is set to move and resize with cell.

View 2 Replies View Related

Positioning Of Validation Input Message

Apr 2, 2009

is it posible to control the positioning of the pop-up data validation input messsage box via vba? As often it obscures the view of critical cells below.
You can manually click and drag it to a desired position manually. Mana users are not aware of that. It would be desirable to reposition it elsewhere rogramatically.

View 2 Replies View Related

Resizing Charts And Positioning Legend

May 4, 2007

I have made charts in VBA charts that needs to be placed on specific position and have specific sizes on a chartsheet. I use plotarea (top, left, width, height) for that. Unfortunately when I set these values they keep chaning, there is some scaling going on in Excel and they won't get the specified size. I have been looking on the internet and finally I found a piece of code which works, but still not good enough, because the legend is also not good positioned

De data for resizing the new charts (ChtNew), the legends and the charttitle I get from other charts (ChtOrig). The legend.legendposition of ChtOrig does not have a value but it still have a top,left,height en width which I use.

I show you my code, the part with the for-next is taken from the internet.
I am trying to find a solution now for 3 days and now I only dream of huge charts (which is not good). So please can someone help me with this? This is the last forum, that I can try, I didn't get reactions from others.

with ChtNew.legend
.Top = ChtOrig.Legend.Top
.Height = ChtOrig.Legend.Height
.Left = ChtOrig.Legend.Left
.Width = ChtOrig.Legend.Width '* 1.1
.Top = ChtOrig.Legend.Top + ChtOrig.ChartTitle.Top
end with

With ChtNew.Plotarea
.Top = ChtOrig.PlotArea.Top
.Height = ChtOrig.PlotArea.Height
.Width = ChtOrig.PlotArea.Width
.Left = ChtOrig.PlotArea.Left

For i = 1 To ChtOrig.PlotArea.Top........

View 9 Replies View Related

Positioning Input Validation Message Box

Jan 9, 2008

I am using data validation input messages for data entry tips/definitions. The data entry cells are grouped in small tables (about 5 rows X 6 columns) so when the user clicks on a cell, the data validation input message box pops up next to the active cell. This covers the adjacent cells which need to be completed as well.

If I drag the message box over to right of the input table, the messages for the other cells stay in the new location as well. However, Excel doesn't remember this location the next time the workbook is opened.

Is there a way to set the location of the message box or some other way to achieve the same objective of having text boxes pop up in a defined location when a cell is activated?

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved