Copy and paste to new sheet - vba

I am trying to copy a row of data from one sheet to another having run some other macros, however I keep getting the error message that the paste area and copy area are not the same size and shape.
I have tried using special cells paste method but it seems be missing the data from the last 9 columns.
Code:
id.EntireRow.SpecialCells(xlCellTypeConstants).Copy
missingdata.Range("A" & Rows.Count).End(xlUp).Offset(1,1).PasteSpecial xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
I need help changing the code so it copies the full row of data and pastes it under existing entries in missingdata.
It seems when it works when I choose to paste in Column A, however it does not allow me to paste from column B

I normally use:
Rows(index).Copy
Cells(1,Rows.Count+1).Select
ActiveSheet.Paste

Related

Highlighted cells that use formulas won't copy the highlight to another sheet

I have a macro that highlights cells in a column that uses formulas.
I'm using this code to highlight the cells:
With Sheets("Sheets1").Range("G:G").SpecialCells(xlCellTypeFormulas)
.Interior.ColorIndex = 6
End With
However, I'm trying to use another script to copy this data from Sheet 1 to Sheet 2 and when I run the script, the highlighting is removed from the cell but the data is still copied into the new sheet (Sheet 2).`
Sheets("Sheets2").Range("G3:G100").Copy
Sheets("Sheets2").Activate
Sheets("Sheets2").Range("A1").Offset(0, l - 1).PasteSpecial xlPasteValues`
I need assistance trying to copy the cells over to the other sheet and to maintain the highlight on the cells that use a formula.
Thanks in advance!
Because you are pasting values the formats don't come along. Add a second paste as follows:
Sheets("Sheets2").Range("A1").Offset(0, l - 1).PasteSpecial Paste:=xlPasteFormats

Pasting same cell on different rows as value is replaced

This sort of follows up from my previous few questions on the same workbook.
I have two sheets, the first being Car Search, which contains a form (NOT a VBA form, just a normal table that appears like a form) to fill in. The second sheet is Raw Data, and will contain all the information entered in the Car Search sheet. It will be displayed row by row (see 2nd image).
In the Raw Data sheet, I am using the formula =""&'Car Search'!B3 to copy the contents of cell B3 in the Car Search spreadsheet.
My question is: If I had a new Car ID value, how can that automatically be entered into the row below?
Essentially, I am trying to use the form to capture all data for new cars coming in, and then I would like all that data to appear in the second sheet in their respective rows/columns.
Any help much appreciated! :)
EDIT:
Good news!
You need to use VBA:
Sub Range_Copy_Examples()
Worksheets("Car Search").Range("B3").Copy Worksheets("Raw Data").Range("=OFFSET(Sheet3!B1,0,0,COUNTA(B1:B300)+1,1)")
End Sub
However there is a small bug where it keeps pasting across past values, so I have suggested an alternative macro below
Re-edit:
A more mechanical way to make macro work (hopefully someone can improve on it) looks like this:
Sub Macro1()
Sheets("Car Search").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Raw Data").Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Worksheets("Car Search").Activate
End Sub
This works as follows:
in Car Search, have cell B3 selected the whole time
in Raw Data, select the cell with the last value in the column where you want you Car Search!B3 data pasted (you only have to do this once)
press Run on the macro (easy enough to just record one yourself)
go back to Car Search and change the value of B3, press Ctrl-Enter to keep the same cell selected after changing value, then press the same macro button without changing a thing.
If someone could add so that when pressing Ctrl-Enter on Car Search!B3 the Raw Data gets automatically added without having to manually run the macro, it would be fully automated!

Problems with paste as values in VBA

I have a problem in paste as values a multiple selection, this is what I have to do:
I have a spreadsheet, every cell has a formula in it and I want to create a macro which copy each cell and paste on itself as value (in order to remove every formula). The problem is that there are some cells which are locked, so if I try to copy and paste them excel returns an error and it stops the procedure.
Now I have two possibilities:
case 1: copy and past as values each cell individually, but I have a lot of cells and I have to do this procedure very often.
case 2: create a big selection which contains only the unlocked cells and then copy and paste them all togheter.
case 2 seems to be the better choice, but with excel I can't copy and paste multiple selection...does anyone have a tip for me?
I though to take the big fragmentary selection and copy and paste every block of the selection one by one, but I don't know if is it possible :(
Loop throught every cell in selection and check if they are locked like this:
For Each Z In Selection
if Not Z.Locked Then
'do copy paste here
End If
Next Z

Copy variable range on one sheet to next empty row on another sheet

I need to copy all data in columns P:Y and paste it into the next blank cell in column A.
I've written the code below, which works fine, except that the data it is copying (P:Y) contains a formula down the whole column and although I am pasting values in order to only get the value returned, it is counting all cells as containing data.
By this I mean that when I run the macro the first time, it works. But when I run it a second time, (which I need to do) when it finds the last empty row. It isn't the last empty row! It selects a row far below the actual last row that I can see data in.
There is no data in the empty rows and no formula in them, but for some reason that is beyond me, it is treating the rows as not empty.
The data returned in columns P:Y by the formula will change every month, so I can't define a specific range.
How can I modify the code to rectify this - or is there a better way I could do this?
Sub SelectRangea()
Sheets("Set Up Data").Select
Range("P2:Y10000").Select
Application.CutCopyMode = False
Selection.Copy
With Sheets("Pasted Report")
lst = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & lst).PasteSpecial xlPasteColumnWidths
.Range("A" & lst).PasteSpecial xlPasteValues
End With
End Sub
When a cell contains a formula, it will have a value, even though it seems empty when inspecting the cell on the sheet. So if you copy such seemingly empty cells and paste them somewhere else (even if only as values), the pasted-to cells now do contains something (i.e. they're not really empty anymore; they're an empty string to be exact instead of VBA's Empty).
Range.End will then move to those last empty cells instead of moving to the last true filled cell.
You can see this for yourself if you do this by hand on an empty sheet: enter in A1:A5 the formula ="", then copy the range as values to B1:B5, then select B10 and press Ctrl-Up.
A fix would be to use the Range.End method, and then just inspect the cell contents going upwards. Or use Range.Find, but keep in mind that that also alters the settings in the user's Find dialog.

select rows/columns dynamically in excel

I m trying to select rows/columns using vba. I want to pass row numbers through a textbox Rows("2:5").Select
Here 2 and 5 shall be passed as variables..Once passed the rows shall be selected and copied to a specified location in the same sheet. I m new to excel and learning using macros. May someone pls suggest a way out.
This is the script for copying ....
(your can pass the row numbers as arguments and concat them as String)
Rows("1:13").Select
Selection.Copy
Suppose you want to paste to some other sheet
Sheets("Sheet2sa").Select
ActiveCell.Select
Selection.Insert Shift = xlDown