Find cell address and add a hyperlink based on a tab name - excel-2007

I have a multiple tab (200+) workbook where each tab has a specific 3-5 digit name. Tab's name goes into A1 of each respective tab via formula =RIGHT(CELL("filename";A1);LEN(CELL("filename";A1))-FIND("]";CELL("filename";A1);1)) This is working ok.
I need all A1's to become clickable (hyperlink) to jump me to a specific cell in the first tab (MAIN) in the workbook, where I have a column of all tab names listed (C6:C280 & growing). This was the plan -
=HYPERLINK(**xxxxxx-add_here-xxxxxxxxx**;RIGHT(CELL("filename";A1);LEN(CELL("filename";A1))-FIND("]";CELL("filename";A1);1)))
Tried adding something like (#'MAIN'!C)&MATCH(RIGHT(CELL("filename";A1);LEN(CELL("filename";A1))-FIND("]";CELL("filename";A1);1)));MAIN!C6:C280;0) , but there is a mistake somewhere.. Pls correct or suggest a better/simplier option. Thank you :)
This is a shared file, so no VBA/Macros/conditional formatting, etc allowed.

=HYPERLINK("#Main!C"&MATCH((RIGHT(CELL("filename";A1);LEN(CELL("filename";A1))-FIND("]";CELL("filename";A1);1)))*1;Main!C:C;0);RIGHT(CELL("filename";A1);LEN(CELL("filename";A1))-FIND("]";CELL("filename";A1);1)))
Ok, couple days fiddling and I came up with the solution myself. The above string works. Looks like the issue was with formatting as when the tab name is multiplied by 1 (thus making it a number) everything starts working. Go figure..

Related

Select all headings through VBA

I am trying to achieve what the "Select all instances" option does upon right clicking a Heading style. Recording a macro while clicking the button returns nothing.
The problem I am trying to solve is that when I paste a document into another one, the numbering of the headings do not update, even though the style is the same. This is fixed when I manually select the heading and click on its style again.
I have found this code:
docSource.GetCrossReferenceItems(wdRefTypeHeading)
But it only gives a string list of what each header contains, therefore I would have to do additional loops to find these in the document and reapply their styles.
Is there any other way to select or loop through the headings of each style in the document to update their numberings?
Is there perhaps another approach to solve the initial problem of the numberings not updating in the first place?

Excel copy all values from one main sheet to various other sheets if they are a certain colour

Would really appreciate a solution to the below:
I am looking to have 8 sheets.
Main sheet that has all jobs, these are all currently sorted into the following colours :
Red - live
Green - invoiced/complete
Blue - quoted
Black - enquiry
Grey - dead/ lost
Purple - work in progress
Yellow - Retention
what i would like to do is keep the main sheet and have a sheet for each of the above. when the text becomes red for example i would like it to be transfered to the live sheet and vica versa for the rest. this should be in a macro
can anyone help?
Many thanks,
You say "when the text becomes red " so possibly this is a conditional format?
In any case, what you need to do is to attach code to the main sheet's Calculate event . This code should do the following
look at the activecell's color element that you mean (font, background, conditional formating, etc)
Based on that color, copy the entire row to the appropriate sheet
(Can you assume the sheets already exist?)
You will probably need a Select Case Statement. I would declare a worksheet variable and then SET it to the appropriate sheet in the select
and then
Activecell.entirerow.copy ws.cells(ws.rows.count,1).end(xlup).offset(1,0)
will copy the row to the desired sheet at the bottom of any existing rows.
Have a try and come back with code if you get stuck
EDIT: Sorry I missed the "click a button" part. You can ignore the bit about the sheets calculate event - just attach your code to the button. The only thing to worry about then is that you will need to run through all the used rows of the sheet, since there might be more than one coloured row when you click on the button.

Trouble with Copying VBA Code

I've been working on an independent project for a client of mine. They wanted to produce a button that, upon the user-click, it would open up a user-form and have a variety of macro-related options to choose from: a drop-down list, checkbox, option select button, etc.
I created a test formula and submitted it to the client; they enjoyed it thoroughly and decided to sent me a file to 'copy & paste' my original code within their excel file.
Problem is; because I'm a tad bit inexperienced with VBA I've run into a problem where once I click the button - the user form doesn't show up.
Below is a Dropbox link of the original file I created and it's original code; as well as the file that I am trying to copy.
Any help would be all welcome and appreciated.
Link to dropbox: https://www.dropbox.com/sh/l1t37lz8uritrua/AAAdWPGvw0GDZ6hW4SwmbBdRa?dl=0
OriginalProject.xlsm has a form named honor_roll_form which contains 100 lines of code.
CopyOfOriginal.xlsm has a form named UserForm1 which contains no useful code.
I do not believe there is any method of directly copying user forms from one workbook to another. Instead
Within VB Editor of OriginalProject.xlsm, select honor_roll_form.
Click File then Export File and save the form on your desktop or where ever you like.
You will now have two files on your desktop; one with an extension of frm and one with an extension of frx.
Within VB Editor of CopyOfOriginal.xlsm, click File then Import file.
Import honor_roll_form.frm
When I try clicking button "Honor Roll", I get "Method or data member not found" for project1Box. I will investigate after dinner (18:57 here) unless you tell me you already know why I am getting this error.
Extra comments in response to request from OP
It is late here but I have started looking down sub execute_button_Click within the second CopyOfOriginal.xlsm. I will comment on what I see even if it is not directly relevant to the non-execution of the macro.
If you open the VB Editor and look on the left you will see the Project Explorer. Near the top you will see:
Microsoft Excel Objects
Sheet1 (Sheet1)
I have always found this confusing. The first “Sheet1” is Excel’s Id for the worksheet and cannot be changed. The second “Sheet1” is the default name for the worksheet which can be changed. You can write Sheet1.Range("A1") or Worksheets("Sheet1").Range("A1"). That is: you can reference a worksheet by its Id or its name. You have named a variable of type Worksheet as Sheet1. Using Excel’s names as variable names can lead to bizarre errors so it is important to avoid doing anything like this.
It is better to always use meaningful names. At the moment, you know what Sheet1 means but if you come back to this macro in six or twelve months will you remember. I would use a variable as you have but I would name it WshtCis208 or WshtVBAProg or something similar.
Set ID = Range(Sheet1.Cells(2, 1), Sheet1.Cells(52, 1)) could be written as:
With WshtCis208
Set ID = Range(.Cells(2, 1), .Cells(52, 1))
End With
Using With statements produces faster code and, almost always, code that it easier to read.
“52” is the current bottom row for this table. Will you amend the macro for them every time they add or remove a student? There are several techniques for finding the last row, none of which is perfect in every situation. The technique that is the most convenient most of the time is:
Const ColCis208Id as Long = 1
Const ColCis208MidTermExam as Long = 5
Dim RowCis208Last as Long
RowCis208Last = .Cells(.Rows.Count, ColCis208Id).End(xlUp).Row
At the moment, column 1 is the Id column. It is perhaps unlikely that the Id column will move but it is very likely that some of the others columns will move when some new column is identified as useful. Do you want to scan the code trying to decide which 5s refer to the MidtermExam column when a Project3 column is added?
Constants allow you to name literals that might change. It makes your code easier to read and saves so much pain when a value changes.
.Rows.Count gives the number of rows in a worksheet for the current version of Excel so .Cells(.Rows.Count, ColCis208Id) identifies the bottom cell of column 1. End(xlUp).Row says go up until you hit a cell with a value and returns its row number. It is the VBA equivalent of Ctrl+Up.
The next statement subjectCount = … fails because projectBox does not exist on the form. You have changed the captions but not the names.
As far as I can see the form fails to execute because you have started updating it but have not finished.

How to get defined table name in Excel?

I have an excel file with several sheets with assigned to them alliances. One of value on one sheet is calculating by using code below:
VLOOKUP(D10; lst_table_col; 4;00);
It doesn't matter that VLOOKUP function do, that matters is what exactly sheet behind lst_table_col. The problem is that this excel file doesn't contain any lst_table_col sheet. I'm looking for any solution: by just mouse, vba - whatever.
I believe my question is very easy, but this situation confuse me.
You must have a table called lst_table_col
Because if it was a direct reference to an Excel Range, you would see something like this in the formula :
SheetName!R1C1:R10C4
or
A1:D10
so check in Formula Tabs -> Name Manager to find it! ;)
Here is the link for the tutorial provided by #Rocketq : https://support.office.com/en-ca/article/Define-and-use-names-in-formulas-4d0f13ac-53b7-422e-afd2-abd7ff379c64#bmmanage_names_by_using_the_name_manage

Formatting Marks also show and hides tables

I have a weird bug.
The below report is built from from a complex Excel Macro and below is a single page from the report output. The page is built from a range so the report is all in tables which is fine.
https://drive.google.com/folderview?id=0B-A_d72xVQXtfmVQUFFHdmVvUUdldUpLT1dmRnk4bXowaDNtUWt0eE5yeE1mZHRKNEpyck0&usp=sharing
The problem I am having is that the table Excel has put into this particular page (and about 1-2 others), is that the "show/hide formatting marks" button (e.g. the backwards P at the top of word) also show and hides the table and anything in the table.
I can expand on this as much as needed and have provided a download link as the only way to really show it is for it to be seen by turning the formatting marks on and off. I have removed text on that sheet as some of it is sensitive.
Excel code being used to copy and paste is below. This code works fine for the other 100-200 pages.
Sheets(curr_sheet).Range(sp(0), sp(1)).Copy
oDoc.ActiveWindow.Selection.Paste
any ideas?
I have found the answer thanks to #Tim Williams pointing me in the right direction.
It was because of the hidden text flag being set to true, I do not know how it got set to true as I can not find any reason for it to be.
Anyway if anyone else is looking this sloved my problem
oDoc.ActiveWindow.Selection.WholeStory'select everything
oDoc.ActiveWindow.Selection.Font.Hidden = False'Turn hidden off for whole document