I'm very new to Excel VB scripting and i'm looking for information on how to copy specific cell data to a new sheet with a table and add a new line for each time you press the button to copy. Let me try to explain better
I have 1 sheet named Values and one named Data
Excel Version 2013
Value Sheet Information
in Cells A2, H17, H19, H21, H23, H25, H27, H29, H31, H33, H35 and H37
Data Sheet
Tablename: SurveyData
Table Header names
AgeRange, B1, C1, D1,E1, F1, and so on all on the same row
H17 = B1
H19 = C1
And so on
When you click on the button it should copy all these values from these cells to a new table row in the Data Sheet
I don't know how possible this is to do within Excel but i'm hoping there will be some options on how to perform this within Excel.
Thank you for taking your time and hope this explanation of mine makes sense.
Edit: I did a huge error when expressing my request, The data in the entry sheet is spread out across multiple rows and cells. I want to take these individual cells to be pasted into a new sheet on a new row. so it will look something like this
When you click the button it copies all data from Sheet 1 to Sheet 2 each click creates a new row with data filled in on each cell that was copied from sheet 1 under their corresponding cell.
AgeRange B C D E F G
15-20 1 1 0 1 0 1
20-25 1 0 1 1 1 0
And so on.
I got the copy down but getting each individual cell to be pasted into one row in a new column and when done go to a new line for new data is the issue.
I do not know if i make any sense here
Regards
Johan
Sub CopySheet1PasteSheet2 ()
count=Worksheets("Sheet1").Cells(Worksheets("Sheet2").Rows.Count, "A").End(xlUp).Row
Worksheets("Sheet2").Cells(count+1,1) =Worksheets("Sheet1").Cells(1,2) 'for A2
Worksheets("Sheet2").Cells(count+1,2) = Worksheets("Sheet1").Cells(2,5) 'for B5
End Sub
In order to add next row you need to count rows in Data Sheet:
Dim count as integer;
count=Worksheets("Data").Cells(Worksheets("Data").Rows.Count, "A").End(xlUp).Row
To copy values from worksheets from A2 to V1
Worksheets("Data").Cells(count+1,1) = Worksheets("Values").Cells(1,2)
And then next cells accordingly
Related
I have two sheets in an excel workbook and Sheet1 has the following columns:
and Sheet 2 has only ID column:
If ID in sheet 2 matches with ID in sheet 1 I want to write col1 and col2 values in sheet1 to sheet 2
I used VLOOK up to identify the matched records but I am manually copying the values of the matched records into sheet 2 and I have to do this for 100,000 rows. I really appreciate if I can get some help.
In your sheet 2, in cel B2 write this formula: =IFERROR(INDEX(Sheet1!$A$1:$C$4,MATCH(Sheet2!A2,Sheet1!A:A,0),2),"")
In your sheet 2, in cel C2 write this formula: =IFERROR(INDEX(Sheet1!$A$1:$C$4,MATCH(Sheet2!A2,Sheet1!A:A,0),3),"")
Change matrix offcourse to your needs and drag down!
Edit
Hello,
Trying to copy a row of data from a roster on a sheet into a new sheet when a cell states Line 1
ie When i type Line 1 etc i want excel to automatically take the row of data for Line 1 on my data sheet and insert it into the target row, cannot use VBA
Appreciate help, i am a beginner
If your data is in A1 to E2 in Sheet1 and your formula in Sheet2:
=IF(Sheet2!A2="","",INDEX(Sheet1!$A$1:$E$2,Sheet2!A2,COLUMN(Sheet2!B2)-1))
Now type into cell A2 in Sheet2 the row you want the data from in Sheet1. Drag the formula to the right or down by clicking on the lower right corner.
I have two sheets:
Sheet1 contains many rows with a lot of data in them. Each row has a unique number in column A.
All these data from the rows in sheet1 is copied to sheet2 with a simple =sheet1!$A$1 ect.
Sometimes/a lot of times I need more than one copy of the row (exact copy) in sheet2 and at the moment I am manually inserting a new line in sheet2 and I am copying the above row to the newly created row.
Now, it would be very nice and very time saving for me, if I in sheet1 could insert a new column, in which I could define how many copies that would have to be created in sheet2. It would also be nice, if I could change the number of copies afterwards (in sheet1), if I by mistake had punched in the wrong number there, and then excel automaticly would delete the number of copies that where to much, starting by the last row created.
Any ideas on how this could be made?
Code I have tried:
Sub copy()
Set i = Sheets("Sheet1")
Set e = Sheets("Sheet2")
Dim d
Dim j
d = 1
j = 2
Do Until IsEmpty(i.Range("Q" & j))
If i.Range("Q" & j) = "TERM" Then
d = d + 1
e.Rows(d).Value = i.Rows(j).Value
End If
j = j + 1
Loop
End Sub
This wouldn't be very efficient, but the way you could do that would be to have TWO extra columns in Sheet1.
As you stated, column B would be the number of repetitions you'd want the value from column A to be.
You'd want column C to be a cumulative count. To do this, you'd have:
C1: =B1
C2: =C1+B2
Drag C2 down
Now, in sheet 2, you could put in the following formula AS AN ARRAY FORMULA
A1: =INDEX(Sheet1!A:A,MATCH(TRUE,Sheet1!C:C>=ROW(),0))
(To make it an array formula, once you type it in, finish with ctrl + shift + enter.)
Drag, Sheet 2, A1 down for a lot of rows and that will update as you change the values in column B of sheet 1 (the number of times to repeat the value in Column A)
Hope this does the trick!
I have a excel workbook with 3 sheets, sheet1 contains all the data which is split into remanning 2 sheets.
sheet1 data is updated on daily bases therefore i need to split sheet1 and update the reming two sheets, so at the moment i copy a each row from sheet1 and replace corresponding row in sheet2 or sheet3 with new data , each sheet contains the same columns: customer_id, customer_name, customer_surname, customer_deposit, total_deposits.
This requires so much manual work is there way where i can just automatically update a row in sheet2
and sheet3 with the data from sheet1.
Ps. The customer_id never changes so maybe there is a way i could use this t update the rows....?
If you only use sheet 2 & 3 for viewing the data then you can do something like this:
In sheet 2 set the formula for A1 to be
=(Sheet1!A1)
then drag the cell to the left (copying the formula) for however many columns you want. Then drag the higlighted cells down to copy the formula to all the desired cells. Then do the same on sheet 3 but starting at the point you want to split sheet 1. Then update sheet 1 and sheet 2 and 3 will automatically update.
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...