Excel VBA - combining worksheets from multiple workbooks and rename new worksheet tab - vba

I am trying to create some VBA code that will do the following:
Take worksheets 2 and 3 from a number of different workbooks (all in the same folder) and put them into a new workbook.
Worksheet 2 has the same name in each of the different workbooks so I want the VBA to also change the name of the new worksheet to a cell reference from the original worksheet (in this case cell A6)
Worksheet 3 has the same name in each of the different workbooks so I want the VBA to also change the name of this new worksheet to the same cell reference (A6), combined with the text "ph"
Any help would be gratefully received
Rob

You'll be able to figure out all of the code you need with the help of the Macro Recorder. Turn that on and manually do your listed steps (make sure you stop recording when that's done), then look for pieces of code that move the worksheets and rename them. Once you see that code, you can figure out how to customize it to your needs.

Related

using data validation for copying a named chart form another worksheet

I have been working on a dashboard where I can use drop-down lists to select and copy/paste named charts with the same name from other sheets in the entire workbook.
I'm trying a few things but none works:
Activeworkbook.ChartObjects Range("F2").activate
F2 being the cell with data validation.
I think your select isn't working because you need to use the value in your cell as a string referring to the chartobject in the collection. Change the sheet reference below as needed. I have my cell containing the name of the chartobject and the chartobject itself on the same sheet but it sounds like that's different than your setup.
ThisWorkbook.Sheets("Sheet1").ChartObjects(ThisWorkbook.Sheets("Sheet1").Range("F2")).Activate
Which you could then shorten if you have workbook and worksheet variables referring to ThisWorkbook, your worksheet with your chartobject, and your worksheet with your data-validated name cell.
Thank you for that! It solves the first part of the question, namely using the value in the cell as reference.
The second part is more tricky: I have several sheets with named charts in the workbook and I need the command to copy a particular named chart in the entire workbook.
One option is just to put all my charts into a single worksheet. but ideally I would like to keep them in their respective sheets.
Any way this could work?

VBA - Pushing data from one workbook to another, irrespective of file names

Been in a pickle for a while (week or so) here and was hoping someone in this magical community could help me out. There is likely a very easy solution for an experienced individual, which I am not.
First, my goal is as follows: Push data from Workbook A to Workbook B via macro.
Conditions:
Workbook A must be able to be renamed without compromising the macro (it is a tool used in day-to-day functions and saved as a new name each use). Workbook A holds the macros.
Workbook B receives the data. Its name will also change with time, but in this case it needs to be based off written text in a cell from Workbook A (name change about yearly due to versioning) Let's just call it Cell A1 for argument's sake.
There may be additional workbooks open at the same time, related or unrelated.
To keep it simple, I will just post one line in my current macro, but I will be applying this to dozens. This works when I do not rename the files. I likely need help defining variables (strings?) and direction in what functions to use.
Windows("Workbook_B 4.7.5.xls").Activate
'*Workbook B name will ideally be derived from a cell value in Workbook A*
Range("V12") = "='[Workbook_A V1.2.5 .xlsm]SHEET_A '!R8C7"
In this chunk, the goal is to activate Workbook B and copy the value (or formula if it is easier), from cell G8 on Workbook A Sheet A to Workbook B(sheet is already active and sheet names will never change in either workbook).
Cheers!
"Workbook A holds the macros" - in this case you would use
ThisWorkbook
to refer to Workbook A
...and
Workbooks(ThisWorkbook.Sheets("Sheet1").Range("A1").Value)
to refer to Workbook B

Update master workbook with another workbook

There is lots of questions about copying the content of one workbook to another that I'm aware of.
I would like to make a code that updates the workbook by importing the content from the other workbook without rewriting cells, just adding values. I want to make it that way in case the other workbook is corrupted or have some data deleted.
Some rows can be partially filled but the macro will fit the correct information in the right row.
Have you considered trying to copy over the workbook as a different name?
Imagine you start with
MasterWB -> sheet1
ChildWB -> sheet1
You copy over such that you have this worksheets.
MasterWB -> sheet1 , sheet2(childbook)
From there it is pretty easy to do a concat on a third page. First create a third sheet. Next, concat the values on sheet3 with values from sheet2 and 1
MasterWB.sheet3.cellA1.value = concat(sheet2.cellA1.value, sheet1.cellA1.value)
Sorry for the bad syntax, hope this helps!

Bind a cell in one Excel sheet to a cell in another

Say I had two Excel sheets (ONE.xlsx & TWO.xlsx). Would it be possible to have a certain cell in ONE to be changed at the same time as a certain cell in TWO?
For example:
B2 in ONE is equal to "Tuesday". Is there a way to make D10 in TWO also equal to "Tuesday" without having to go into TWO and manually changing it.
The more I think about this problem the more I think that it's not likley to work. The only way I can think of it working is by connecting them both up to the same database somehow. Thought I'd try you guys before I give up try something else.
Thanks in advance!
I've found a solution that works very well.
Open both the workbooks.
In the source workbook, copy the cell(s) that you wish to link.
In the destination workbook, right click and select "Paste Link".
The cells in the destination workbook should now be linked so that when changes are made to the source workbook the changes are also made in the destination workbook.
Sure, open both workbooks.
put = in workbook 2 minimize and find the sheet/cell in workbook one
select it.
close workbook 2 and save.
change the value in workbook 1
open workbook to (enable the security to look at workbook 1)
see the updated value.

Excel VBA loop through columns in range and copy columns

I am new to Excel VBA and need some help writing a macro.
From Worksheet1 of Workbook1 I need to copy each column of range D1:Z100, one at a time, and pasteValue it to cells B1:B100.
This triggers a calculation in Worksheet2 of Workbook1. Here I need to copy cells A1:B200 into a new workbook.
This new workbook is to be renamed with the text string in Worksheet1, cell B1. The new workbook is to be saved into the same folder as Workbook1.
The loop is then to continue with the next column from Worksheet1, and continue until all columns in the range have been treated this way.
I have used two days searching the net to find an answer without any luck....
Start the way most of us did:
Record new macro.
Manually perform all the steps you want to automate.
Stop recording.
Go to the Developer tab and inspect the auto-generated code.
Write your own VBA based on what you learn in Step 4.
You will have to figure out a few things on your own, or come back here and ask specific questions.