Inserting Contents of Range of Cells Into Another Range - excel

I am working on setting up a column of cells in Excel and I would like each cell in the column to pull data from multiple columns of cells from another sheet, with each cell having a one-on-one relationship with each other. For instance, I have Column A on Sheet 1 and it is automatically populated from data in Column A and Column B on Sheet 2 (once Column A runs out of data). If any of the data is changed on Sheet 2, the changes will be updated on Sheet 1. If an item is added, it will automatically be inserted on Sheet 1. Is this possible using standard formulas or array formulas, or do I need to use macros or VBA? Any suggestions would be appreciated. Thank you much in advance.

Either
Copy your formula such as IF(ISBLANK(Sheet2!A2),"",Sheet2!A2+Sheet2!B2 down a greater number of rows than you're likely to need.
or
Write a macro to run each that will copy your formula for you.
lr = Sheets("Sheet2").UsedRange.SpecialCells(xlCellTypeLastCell).Row
Sheets("Sheet1").Select
Range("A2").Select
Selection.Copy
Range("A3:A" & lr).Select
ActiveSheet.Paste

Related

vba offset with reference to cell

I need to copy a column of data to another column on a different worksheet, pasting values only. The appropriate paste column is identified in a single cell. This cell will be changed manually each time the macro is applied. So one time I might want to copy/paste in the first column, so my identifier cell is 1. The next time I might input 5 in this cell so that I offset 5 columns to the right to copy/paste data. Thank you.
You can reference the columns in a worksheet using the Columns property. You can achieve what I think you're trying to do with code like this.
Dim col As Integer
col = SomeSheet.Cells(1,1).Value
FromSheet.Columns(col).copy
ToSheet.Columns(col).PasteSpecial xlPasteValues

VBA auto select last filled cell

I have an excel sheet with data. I have some VBA that will filter the sheet to a specific value and then move down to the last filled cell.
ActiveSheet.Range("$S$2:$S$1218").AutoFilter Field:=1, Criteria1:= _
"Scheduled"
ActiveSheet.Cells(ActiveSheet.Rows.Count, Selection.Column).End(xlUp).Select
This works fine for the purpose. However, column A has numbers filled out past where I want it to stop. Could this be edited to only query column F (for example) and move down to the last filled cell in column F.
Thank you!
In vba coding, cells are typically denoted as cells(i,j) where i represents the number of row while j represents the number of column.
Since you want to work on column F, which is column no 6, you just have to change the code accordingly like this:
ActiveSheet.Cells(ActiveSheet.Rows.Count, 6).End(xlUp).Select

Copy "X" rows of Data

I need to build a macro that allows me to copy a range of data to the clipboard but that data is stored in a daily changing number of rows. To clarify, I have two tabs on this blank worksheet that I fill out every day. Tab 1 is called "Recap", and based on what I type into the "Recap" tab I have data pulling into my second tab called "Exception Log" through "if" formulas. The data pulls into A8 through F8 and Column E is blank so that if I copy A8:F8 it matches the formatting in another spreadsheet where I will paste the data. Some days there are only 3 rows of data meaning I want A8:F10 copied into the clipboard but other days there is 30 rows of data meaning I want A8:F37 copied into the clipboard. In an attempt to try to make this a little easier I added a basic count formula to Cell H5 that counts the number of rows with data in them and therefore the number of rows that I want copied from columns A to F starting at row 8 but I can't figure out how to work it into a Macro. Any ideas? Thanks in advance!
Example : To copy from a range in sheet1 to another range in sheet2 starting at C6 :
Range("A8:F13").Select
Selection.Copy
Sheets("Feuil2").Range("C6").Select
ActiveSheet.Paste
if your row number is H5 :
n=range("H5").value
Range("A8:F" & n).Select
Selection.Copy
Sheets("Feuil2").Range("C6").Select
ActiveSheet.Paste

Insert the same Non-Blank Rows every nth row

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.

Excel 2007 - Formula changes to #REF

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...

Resources