Pasting data from PowerPoint text boxes into Excel - excel

I have a PowerPoint that I need to copy the numbers in text boxes to a specific excel file. I have decided to use a macro on the PowerPoint because the file will be shared with multiple users and I want to compile each file's data into a spreadsheet. My code works fine so far, but only copies to a specific row and thus overwrites the existing data. I am having trouble with the code for finding the next empty row. What I tried so far only seems to work when going from excel to excel.
rw = Range("A" & Rows.Count).End(xlUp).Offset(1).Select
I am a novice at best when it comes to VBA. Please help.

While xlsWB.Worksheets(1).Range("A" & row) <> ""
row = row + 1
Wend
This will find the next empty row and store the row number within the integer row. xlsWB is an Object which stores CreateObject("Excel.Application").Workbooks.Open("File Path")
Then, use the following syntax to fill in your cells.
xlsWB.Worksheets(1).Range("A" & row) = ""
Also, you can use a For loop to automate it.

Related

VBA paste range with dynamic selection

I read multiple Q&A's, however it's difficult for me to really understand all the long scripts with the usage of different objects.
I am trying to select a range from one worksheet to an other.
I want to keep the range dynamic, because the range can vary every time. By doing so I have used the following script:
Dim range As Long
For range = ActiveCell To ActiveCell.End(xlDown)
Sheets("Stock Report").range("A4" & range).Value =
Sheets("Unique File").range("Y8" & range).Value
However it doesn't do anything.
This script does work, but I would like to keep the last cell dynamic:
Sheets("Stock Report").Range("A4:A9000").Value =
Sheets("Unique File").Range("Y8:Y90004").Value
I have to do this for multiple columns which are calculated by using other files in a different worksheets and need to sort them finally without all the calculations in an other one.
Any suggestions?
OK try.
Sheets("Unique File").Range("Y8:Y" & Sheets("Unique File").Range("A4").End(xlDown).Row + 4).Copy
Sheets("Stock Report").Range("A4").PasteSpecial Paste:=xlPasteValues
Range("A4").End(xlDown).Row gets the last row of the data on the Stock Report sheet and is used to copy down to the same row on the Unique File sheet. I added 4 because your range starts on 8 on the Unique File sheet.
I think your code didn't work because you were trying to use the "range" you created from the Stock Report sheet on the Unique values sheet.

Copy Column Data to New Worksheet and Loop through Columns

I have an Excel spreadsheet with over 60 columns. Each column contains data from a SharePoint survey. The column headers are the actual survey questions that have been imported from a SharePoint data connection. I'm trying to do several things here.
First, I want to copy each column to a new worksheet. (The reason I need to do this is so that I can add the data in each column to a PowerPivot Data Model. PowerPivot recognizes the entire worksheet as one table, so it won't let me select only "Column A" to add to the Data Model, it automatically adds the entire table with all 60 columns).
Since I don't want to manually add 60 new sheets first before this, I'd like the code to copy each column to a newly created worksheet. (the worksheets don't need to be named, I could do that manually, unless someone has an easy way to do this as well!)
Then, I'd like the code to loop through each column performing the copy and paste to the newly created sheet.
I've found some examples of the code here for several related topics, but I'm so new to VBA that I'm having a hard time putting it all together. Thank you all so much for your time!
I've tried the following which does copy it over, but I'm not sure how to add a new sheet and loop through the columns
Sub CopyColumnToNewSheet()
Dim lastRow As Long
lastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Range("A1:A" & lastRow).Value = Sheets("Sheet1").Range("A1:A" & lastRow).Value
End Sub
You should do this instead, please note, there is no error handling, suit to your needs
Sub CopyColumnToNewSheet()
Const MySourcheSheetName = "Sheet1"
Dim CounterColumn As Long
For CounterColumn = 1 To Sheets(MySourcheSheetName).Cells.SpecialCells(xlCellTypeLastCell).Column
Sheets.Add
ActiveSheet.Name = Sheets(MySourcheSheetName).Cells(1, CounterColumn).Value 'ideally the title is unique and it's in the first row of each column
Sheets(MySourcheSheetName).Columns(CounterColumn).Copy Destination:=ActiveSheet.Columns(1)
Next CounterColumn
End Sub

How to delete and add specific columns in multiple excel files

I have a file with 5 columns :
A || B || C || D || E
and I want to delete the E column and add 2 new ones with the same content in the cells. I tried to find a way in excel but it is impossible.
I used MACROS record in excel as people have suggested me to use the MACROS in my original query. But the problem is that the excel files I have, have different row numbers. So, in file one I need to add a new column with 10 rows (same text inside) and in another I need to add 2 rows.
How can I program that in the MACROS? More specifically, I want to convert this:
into this:
I only need the columns shown in picture 2. I no longer need to delete the rest. I use the files to import them on openCRM.
in a excel macro
sub ColReplaceInCurrentSheet ()
dim LastCellRow as integer
'uncomment for removing warning message
'Application.CutCopyMode = False
Columns("E:E").Delete Shift:=xlToLeft
' Define last row of data
Range("A65534").Select
Selection.End(xlUp).Select
LastCellRow = Selection.Row
for each ThisCell in Range ( "E1:F" & LastCellRow)
ThisCell.value='The Value I want here'
next
end sub
Assuming number of row is equal to the last (lower) filled cell in column A (arbitrary limited at 65534 here)
You could put any value that you want in the cell, i set it to an abritrary string here
macro is to put in a extra excel file so you can call it (file need to be open in excel) from any other excel
macro work on current active sheet.

VBA Excel Book to Book copy cell value not formula

I have developed (with help from stackoverflow user: #xificurC ) a VBA macro in excel that copies over a certain range of cells and pastes them, in a table in a seperate workbook. But there are formula on these tables that are relating to pieces of data that are not available with the user permissions on my account. So my question is how can I copy over the actual face values of the cells instead of the formula.
'get all excel files (and only excel files) from specified folder
file_checks = Dir(path & "\*.xls*")
Do Until file_checks = ""
'open file
Set wkbklp = Workbooks.Open(path & "\" & file_checks)
Set wkshtlp = wkbklp.Sheets(1)
'copy data away from original
Set data_return = wkshtlp.Range(start_cell).CurrentRegion
data_return.Copy check_sheet.Cells(check_sheet.Rows.Count, "B").End(xlUp).Offset(1, 0)
'close file without saving to make it all more automated
wkbklp.Close False
'loop through files until all are done
file_checks = Dir
Loop
That was the code that transfers the data from one book to another. I have not found a command that does this, but I'm only amateur so may have used the wrong key words.
Try using pastespecial.
data_return.Copy
check_sheet.Cells(check_sheet.Rows.Count, "B").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
You can use the pastespecial method, I don't see where are you pasting but it will be something like
Range.PasteSpecial Paste = xlPasteValues

Excel - Macro to copy a dynamic row number from one workbook to another

I have tried searching for an answer to this, so far I have had no luck.
The solution I am looking for is regarding two workbooks and being able to copy one row from the source workbook (it has 1000 rows) to another book (to only contain one row at any one time, not including column headers).
The other issue is that the next time the macro is run I need to look at the next row down in the source workbook e.g.
First run copies row 2 (as column headers are in row 1) into row 2 of the other book
Second run copies row 3 into row 2 of the other book (as the program reading this book only looks in row 2).
So I assume a counter is needed in the code?
If there are any suggestions it would be very much appreciated.
You will need a macro to copy the data over and since you are going across macro runs (one row each time the macro is run), you will need to store the value of the row you last copied somewhere outside the macro. Let's call this LastRowCopiedOver
You can store this in one of a few places:
A hidden and protected sheet in the same workbook
A protected cell in one of the existing workbooks
Every time the macro is run successfully, you will update the value for LastRowCopiedOver so that you know what row to pick the next time around.
When you reach the end of the book, you can display a messagebox with a Yes/No question to reset back to row 2.
A Static Function will do the trick.
Static Function RowCounter() As Long
Dim i ' Value of locally declared variable is preserved between calls.
i = i + 1
RowCounter = i
End Function
Each time you call it from your main program, i will increment by 1. Since RowCounter is static, it will remember the value of i is between calls.
Run the following sub several times and watch the MsgBox increment. The current row will be copied to "Sheet2". Replace that with whatever your destination sheet is.
Sub main()
Dim iRow As Long
Do While iRow < 2 ' To skip headers row 1...
' Get next row number.
iRow = RowCounter
Loop
MsgBox iRow ' To show that each time main is called, iRow will be incremented by 1.
' Copy and paste that row...
Rows(iRow).Copy Destination:=Worksheets("Sheet2").Rows(2)
End Sub
You can reset the counter to zero by going in the VBA editor and pressing the reset button (the square) on the Standard toolbar or in the Run menu.
If you save the counter in some protected/hidden cell or sheet, resetting it will be a PITA.
Thanks for the input, I spent a bit of time on a solution for this after reading the solutions above.
I ended up creating a separate excel file, I then used some VBA script to create a counter and then copy one line from the large excel source file to the new file so it only contains one row of data.
I have now amended my QAWP script to run this excel macro and it now sets the data in the script using the new single row spreadsheet.
This seems to be working so far, and it means that I can create new test data separately from the datasheet being used by QAWP.
I have posted the excel VBA script below for reference:
Sub Copy_Next_Record()
Application.Workbooks.Open _
"C:\Documents and Settings\user\My Documents\Personal_Data.xls"
Dim RowCount As Range
Set RowCount = _
Workbooks("Full_Personal_Data.xls").Worksheets("Count").Range("A1")
Workbooks("Full_Personal_Data.xls").Worksheets("Data").Activate
Rows(RowCount).Copy _
Destination:=Workbooks("Personal_Data.xls").Worksheets("Sheet1").Rows(2)
RowCount.Value = RowCount.Value + 1
Workbooks("Personal_Data.xls").Close True
Workbooks("Full_Personal_Data.xls").Close True
End Sub

Resources