using data validation for copying a named chart form another worksheet - vba

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?

Related

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

Copy from cell range on 'sheet1' to same range on 'sheetB3'

I had a hard time formulating the title, but I'll explain better here.
What I want to do is use a VBA-macro that I'm activating from a button click to copy the data found in the range B13:E52 on sheet1 to the same range on sheet"B3", where B3 is found on sheet1 containing the sheet name I want to copy to. This dynamically updates depending on what item is chosen in a list.
I know how to create my button, copy between sheet etc but I'm having a hard time figuring out how to reference the target sheet name that's contained in B3 for the target in VBA.
with sheet1
.range("b13:e52").copy sheets(.range("b3").value).range("b13")
end with
If you are looking to copy only the vlaues (without the formats or formulas), then you can use :
With Worksheets("Sheet1")
Worksheets(.Range("B3").Value).Range("B13:E52").Value = .Range("B13:E52").Value
End With

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!

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

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.

How to use pastepecial to paste a chart as bitmap to another sheet in vba

Is there a way to use the pastspecial method to paste a copyied chart as a bitmap to another worksheet. Currently this is my syntax-
PasteSheet.PasteSpecial (Format:="Bitmap", Link:=False, DisplayAsIcon:=False)
Where PasteSheet is the other worksheet i want to paste to. Currently with this code, it is only pasting in the active sheet. Do i have to use select to copy then select the page i want to paste to, then change back to the sheet I copied from? I hope not as I have a lot of sheets haha.
Thank you
Edit: I have found out that if I Copy the chart as a shape rather than a chartobject I can use the pasteSpecial method to paste to another sheet. That being said it now pastes charts into one another creating one mega chart haha.
GraphSheet.Shapes(chtName).Copy
PasteSheet.PasteSpecial Format:="Microsoft Office Drawing Object", Link:=False , _
DisplayAsIcon:=False
This will work without needing to activate/select Sheet2:
Sheet1.ChartObjects(1).Chart.CopyPicture
Sheet2.Paste
Do i have to use select to copy then select the page i want to paste
to, then change back to the sheet I copied from?
Yes - the sheet you paste into must be active. Use Sheets("mytargetname").Select - just using Activate isn't enough...
If you set
Application.ScreenUpdating = False
your screen won't flash while you do this...