I am very new to VBA coding and don't have very good understanding of what I am doing to be honest. But here I go.
I am looking to see if:
- Can VBA codes have dyname values? So instead of the code saying execute on a set sheet (e.g "Sheet1") that value changes depending a value in a certain cell.
- To trigger a VBA on another workbook. For example I want to run a VBA from Workbook A that triggers a VBA on Workbook B.
To fully explain I want to open Workbook A (and Workbook B if needed, it doesn't matter) and click a button that runs a VBA on Workbook B but on a certain Sheet depending on the value of a cell in Excel A (if the cell says "sheet3" the VBA runs on "sheet3" on Workbook B). I also want cells in Workbook A to reference cells in Workbook B but the the sheet name to by dynamic. For example I have pasted the basic cell reference bellow but instead of having Sheet1
I want it to change depending on the value in a cell.
='[Workbook B.xlsx]Sheet1'!$A$4
I know this sounds very complicates and confusing, but if I could get any help that would be greatly appreciated.
Sub ReportStepOne()
Dim myRow As Long
myRow = 4
Rows(myRow).Value = Rows(myRow).Value
Dim rng As Range
Set rng = Range("A4:AC200")
rng.Cut rng.Offset(1, 0)
Range("A1:AC1").Copy Range("A4:AC4")
End Sub
I want to:
- edit this code to make it fire on a certain sheet
- make it so the sheet name is referenced to whatever is in cell A o Sheet2 in Report.xlsm.
- Run a macro in Report.xlsm that runs the above script (which is called "StepOne" in a file called "Historical Data.xlsm"
Report.xlsm
orHistorical Data.xlsm
? If I understand correctly this code should execute on a sheet inReport.xlsm
, which sheet is based on a cell on sheet2 inReport.xlsm
– SilentRevolutionHistorical data.xlsm
and currently fires on the active sheet. I'm hoping to make it fire on a specific sheet, in which the macro references the "sheet name" from a cell inReports.xlsm
. Then have a macro/button inReports.xlsm
that makes the above macro run. It's a new reporting system that I am trying to develop (I'll have to run this macro approximately 40 times). Thanks for your help @SilentRevolution. Sorry about the confusion. – Jerremy Leedhamhistorical data.xlsm
needs to reference a worksheet to retrieve a worksheet name inreports.xlsm
and then execute the code. the sheet named on sheet 2 ofreports.xlsm
does that referer to a sheet inhistorical data
or to a sheet onreports.xlsm
? Do you always have both workbooks open at the same time, if not which workbook is open? – SilentRevolutionreports.xlsm
. Yeah the sheet name inreports.xlsm
refers to a sheet name inhistorical data.xlsm
. Cell A4 inreports.xlsm
will automatically update with a new clients name, and each client has there own sheet inhistorical data.xlsm
. I'll have both files open at the same time. – Jerremy Leedham