I need to be able to insert the same 5 rows of data between every row on an Excel sheet. The 5 rows are not blank but contain specific data that needs to be repeated. The source of the 5 rows could be on a second sheet or rows 2 through 6 on sheet 1, which ever works best. Copy and pasting manually unfortunately is not an option as there are hundreds of lines. Is anyone able to provide some guidance as to how to accomplish this task?
You can use a formula in your sheet 2 like below:
=INDIRECT("Sheet1!"&ADDRESS(FLOOR(ROW()-1;5)/5+1;1))
By using this formula you will have each rows 5 times dynamically, that as soon as any change on sheet1; data in sheet 2 will be updated.
If you want to make them static Copy your data and Paste them with Values Only option.
You need to use a macro to do this:
Sub PasteRangeEveryNthRow()
Dim RW As Long, i As Long
RW = Range("A" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Range("A1:A5").Copy
For i = 1 To RW Step 1
Range("A" & i).PasteSpecial Paste:=xlPasteFormulas
Next i
End Sub
This code presupposes that you are copying the range A1:A5 from SHEET2 and pasting it every one line until the last data in the column A.
basically, you need to press ALT+F11 to open the VBA window in excel , then go to INSERT>MODULE and paste this code there. Then run this macro from the developer tab in excel.
if you don't see the developer tab in your excel, go to the options and enable it.
Related
I have a main sheet in which I manage my trades for currency on the FOREX. On that main sheet I have made buttons that I would like to hyperlink to the subsequent sheets that hold the daily data for each specific currency pair.
I am able to create a hyperlink to the sheet itself by using the hyperlink function but I want the hyperlink to actually find the first blank cell in column B and then count up 10 cells so that the last ten cells are visible on the sheet.
I have tried using Indirect, Offset, CountA, and Match combinations and variations to no avail. Please help.Main Screen Shot
Daily Sheet Screenshot
To simplify, you can replicate this code for each button. Change only one line for each button (and the subroutine name, of course)
Sub JPY_Daily_click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("JPY_Daily")
myrow = sh.Cells(sh.Rows.Count, 1).End(xlUp).Row - 10
sh.Activate
sh.Range("A" & myrow).Select
End Sub
I have sheet which varies in terms of number of rows. But has 72 columns[A to BT].
Can some one please provide me VBA code to copy the X number of rows to a new sheet in the same workbook n number of times?
Below is the code I have but,Here I am able to copy the 1200 rows but not able to paste it.
Sub test()
nrows = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Sheet1.Rows("1200").Copy
Sheet2.Rows("A1").Select
ActiveSheet.Paste
End Sub
I have even tried
Sheet2.Rows("1").Select
In both the cases I get error "424" Object required. Need help to resolve this issue,later I would like to put a loop to copy it to n sheet to n number of times, each time I would paste it to X*n+1 row, where X is number of rows and n is number of times the rows to be copied. Please assist me to copy for one iteration and if you would give me any pointers to loop I would appreciate the same.
Rather than selecting an entire row or rows for pasting, indicate only the top, left cell of the target range. (Note that if you try to do what you want to do as a user Excel will tell you the target Range has to match in size to the source Range. So as a user you'd click only the one cell before pasting. Same thing in VBA.)
Also, there's no need to actually select the target range in order to paste to it.
Sub test()
nrows = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Sheet1.Rows("1200").Copy
Sheet2.Range("A1").PasteSpecial
End Sub
I want to copy all formulas when inserting a new row in the Excel worksheet. I have some calculation formulas and I am taking some values from another Excel file.
Formulas I am using in this Excel worksheet are as follows:
=IFERROR(VLOOKUP(C4,'list.xlsx]Sheet1'!$A$4:$L$261,3,FALSE),"")
=IFERROR(G6*F6,"")
I googled for a solution. I got 2 ideas.
one to make a table with these data.
I tried this one. Formula no:1 worked perfectly. But 2nd formula didn't copy to next line.
The second one to use a VBA code. which works only one time. When open excel next time I have to create VBA code again. also, it needs to click in between cells to create next row.
I want to create a new row when right click on the sl no(leftmost column) and click "insert".
Please help.
Sorry im new in SO but i want to help you:
You using conditional blocking for example : $A$4:$L$261
=IFERROR(G6*F6,"") doesnt copy anything
In VBA you got function PasteSpecial whats copeing a formulas from
cell, here some ex. of using that:
With Worksheets("YourWorksheet_name")
.Range("Your_cell_input").Copy
.Range("Your_cell_output").PasteSpecial Operation:=xlPasteSpecialOperationAdd
End With
If i good understand u want a maro what pasting a forulas when new rod is added. I recommend to use something like this:
Let's make a demo that You have formulas on colmn C to copy that(its affecting column A)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = ActiveCell.Column Then
refRow = Target.Row - 1
thisRow = Target.Row
Range("C" & refRow).Copy Range("B" & thisRow)
End If
End Sub
Anyway please add some more code what u have or screenshoots what u expecting
I need a macro code to delete every 58th row and 4 more rows after the 57th row.
i.e I need to delete row numbers 58,59,60,61 and 62nd (5 total).
I need to repeat this pattern on the entire sheet. So in effect after the macro deletes the 58,59,60,61 and 62nd rows, it needs to delete 115,116,117,118 and 119th row (difference of 57 between them 115-57 = 58).
I tried looking up on the internet, but could not find an article matching my needs. Any help will be appreciated.
Thanks.
For a non-code method you could choose a blank column beside your data and try these steps:
Select the range e.g. A57:A60 and enter X with ctrl+enter to fill the cells
Select the repeating range e.g. A1:A60, and fill down to the end of the data (or use copy/paste)
Press Ctrl+Shift+\ to select all the X's (goto special... column differences or use autofilter)
Choose Delete > Sheet Rows from the Cells section of the Home Tab
You're done. This also preserves the undo stack so you can backtrack if required.
Next time you post a question, you would get better attention and feedback if at least you tried something, anything really. A good first step is to run the macro recorder in Excel, delete a few rows and check the code that has been generated. From there, the final solution is not very far.
Sub deleteRows()
Dim i As Long
Dim maxRow As Long
maxRow = ActiveSheet.UsedRange.Rows.Count
For i = 58 To maxRow Step 52 'Step 52, not 57, because we delete 5 rows each time
Range(Rows(i), Rows(i + 4)).Delete Shift:=xlUp
Next i
End Sub
So I've got this Workbook which contains a lot of data. And I've got this one sheet which basically copies the data based on certain conditions.
Each cell in each row looks like this (the last specified cell is the one where the formula is in):
=IF(Numbers1!E2<>0;Numbers1!A2;"")
=IF(Numbers1!E3<>0;Numbers1!A3;"")
=IF(Numbers1!E4<>0;Numbers1!A4;"")
=IF(Numbers1!E2<>0;Numbers1!B2;"")
=IF(Numbers1!E3<>0;Numbers1!B3;"")
=IF(Numbers1!E4<>0;Numbers1!B4;"")
So the formula in cell A2 is the first one, formula in A3 is the second line etc.
I want to copy the value from the same column and row from the sheet Numbers1, IF the value in the same row of column E is not 0. This seems to be working just fine.
But, when I update the data in Numbers1 sheet, the formulas are all of a sudden invalid and the formula now looks like this:
=IF(Numbers1!#REF!<>0;Numbers1!#REF!;"")
Each formula in each cells look identical to the formula above. And I can't have that, why can't Excel just keep the formula as it is without "helping" me?
Since you may be better off using a macro to rewrite your formulas, here are the basics:
Sub RewriteFormulas()
Dim row, col As Integer
row = 1 'row you want your target formulas to be on
For row = 1 To 60
For col = 1 To 13
ActiveSheet.Cells(row, col).Formula = "=IF(Numbers1!" & Cells(row,col).Address & "<>0,Numbers1!" & Cells(row+2,col).Adddress & ","""")"
Next row
Next col
End Sub
You can play around with using different sheets (or different workbooks) instead of just ActiveSheet so you can have 1 workbook that stores the macro and alters data in whatever workbooks provide your updated datasets.
Hope that helps...