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
Related
I have a long list of names in my "Main Sheet". I need to loop through these rows, create a sheet with the same name and then add a hyperlink to that sheet.
I was able to create the sheets, but I can't create the appropriate hyperlink to the matching sheet.
Here's a snippet of the code:
'HERE, I COUNT HOW MANY INDIDUAL ROWS THERE ARE IN COLUMN A'''
Sheets("MainSheet").Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Total = Selection.Count
'here, I copy the cell value and create a new sheet, using the cell value as the name
'Since some cells had more than 31 characters, I had to create a code to only take the first 30 characters
For i = Total To 1 Step -1
Sheets("MainSheet").Cells(i, 1).Select
Take = Left(ActiveCell, 30)
Sheets.Add.Name = Take
Worksheets("MainSheet").Activate
Worksheets("MainSheet").Cells(i, 1).Select
Next
The code works.
I now need to loop through the same list and create the appropriate hyperlink.
Here's an example of the rows:
Temperature Probe and Data Sensor A1
Temperature Probe and Data Sensor A2
Temperature Probe and Data Sensor A3
Temperature Probe and Data Sensor A4
Air and Pressure Sensor A1
All of these will have their own sheet, but I would want to click on the cell value to bring me directly to that sheet, without having to manually search through 200+ sheets. In short, the mainsheet will act like a directory to the rest of the Excel workbook.
To link in the same workbook, use a formula with this format, =HYPERLINK("[Workbook]Worksheet!A1", "Link Text"). For more info see Work with hyperlinks in Excel.
You can even make the formula find the workbook name, assuming the workbook name and file path don't include any square brackets. For more info see this page. The formula is =HYPERLINK(MID(CELL("filename"), FIND("[",CELL("filename")), (FIND("]",CELL("filename")))-FIND("[",CELL("filename"))+1) &A5 &"!A1", "Link Text"). Change the last part of that formula, where A5 is a cell with a worksheet name, A1 is the link's target, and Link Text is any text or a cell reference.
If you paste the formula with code, then use two quotation marks to paste one quotation mark in the formula, ActiveCell.Formula = "=HYPERLINK(MID(CELL(""filename""), FIND(""["",CELL(""filename"")), (FIND(""]"",CELL(""filename"")))-FIND(""["",CELL(""filename""))+1) &A5 &""!A1"", ""Link Text"")".
Or... Here's a post about how to add a table of contents to your workbook. Maybe you can just save and run a separate macro.
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
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
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.
Say if I select cell A2, and cell A2 has data validation in it and other cells in same row no.2 have vlookup and other formulas in it.
Now I want to insert a blank row below row no. 2 with no formulas being copied from row 2.
I should be able to give a fixed location of the cell in the macros below which I want to insert the blank row
Till now i have been using this:
Range("A3").EntireRow.Insert
This is working fine for me:
Range("A3").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove