Change an excel function into vba code - vba

I have written 2 Excel functions to copy data to cell G12 when data is entered in cell F12
=IF(ISBLANK(F12)," ",(F12))
if data in the deleted from cell G12 it is copied to H12
=IF(ISBLANK(G12),(F12)," ")
these work perfectly but I was wondering if the same procedure can be carried out in vba on a dynamic range as I want to keep adding rows

To achieve your requirements, you can format your range as a table from Home>Format as Table. Now, assuming your table as two columns respectively named "name" and "non blank name", you can enter the following formula in the second cell of the second column:
=IF(ISBLANK([#Name])," ",[#Name])
As you add rows to the table, the formula will be copied automatically to the new row.

Related

generate a hyperlink in sheet linking to matched data found in a different sheet

I have two different sheets in a workbook with data, all of this data is organized by Site ID's. What I want to do is use these site ID's to create a hyperlink in one of the data sheets that when clicked takes the user to the corresponding Site ID in the other sheet. The sheet name where I want to write the hyperlinks to is called "Report_Manual" and I want to write hyperlinks down every row down the first column. The sheet that I am hyperlinking to is called "Data". The premise Ids are located in column C for sheet "Report_Manual" and column K in sheet "Data". Below is an a ttempt of what I was trying to generate in excel for a single cell formula however the issue I ran into for this formula is that the Premise ID's in sheet "data" are variant data type while the Premise ID's in sheet "Report Manual" are integer data type. This makes even a simple formula like the one below not get any matches as the data types being matched aren't the same.
=HYPERLINK("#"&CELL("address",INDEX(Data!K3:K580001,MATCH(C3,Data!K3:K580001,0))),C3)
If anyone has any idea of a macro to solve this issue that would be extremely helpful.
If the IDs in "Data" are text, try changing your match lookup value to text:
=HYPERLINK("#"&CELL("address",INDEX(Data!K3:K580001,MATCH(TEXT(C3,0),Data!K3:K580001,0))),C3)

Copy and Paste to Blank Rows until Blank in Other Column

I am trying to copy and paste A8:P8 in to the Blank Rows (as per pic below) until the data in column Q is blank - is there a VBA which can do this? I need to do this on multiple tabs so the row number will be variable.
Although you could accomplish this with VBA, have you tried just using cell formulae?
For example, in the first empty cell in column A you'd put:
=$A$8
then the same for each other cell in the row, changing the column letter.
Then select all of the cells with formula and double-clicking the autofill handle which will copy the formula down to the last row with data in the adjacent column.

Trying to get the Column Values in 1 sheet to other sheet in Row with Dynamic Updation from 1st sheet

I have been trying to get the above data which is presented datewise in Column form to be pasted in the below format in Row form, but challenge is either 1 date at a time can be taken or either single cell reference needs to be given in each cell on other sheet, need some shortcut such that sheets data remains dynamic and datewise data is copied. Image shows it in one sheet, above data is required to be shown in below format in other sheet.
Thanks and Regards
Mandeep Goraya
For example, your table is like this:
Put this code into cell B8 then fill right:
=INDEX($B$2:$F$3,MOD(COLUMN(A1)-1+ROWS($B$2:$F$3),ROWS($B$2:$F$3))+1,1+INT((COLUMN(A1)-1)/ROWS($B$2:$F$3)))

How to substract two cells of x row on excel

I'm making an Excel sheet to keep track of some activities. The thing is that I have 2 cells that are date type; I want the third cell to subtract the them to get the time that the x person spent on the activity.
I know that if I type =A2-A1 it's going to give me what I want, but, since its going to be a big Excel sheet with lots of records, I don't want to input the same formula for each row just changing the row number.
Is there a way to make Excel detect the row that the user is inputing data in and then make the requested formula to get the time?
you can turn your data range into a table by highlighting the range and going to the insert tab and clicking table. Then when you type the formula into the first cell and click in the cells when selecting instead of typing it out, you will notice that it is using the column names instead, also it will automatically fill the column with the new formula. That would be my suggestion.

How To Display Excel rows on selection of first Excel Column Value

I have Two Excel sheets. My requirement is when I select a reason value from one Excel sheet Reason_Name column, it will display that reason value in a second Excel sheet.
So using Macro, I want to display the second Excel rows on selection of reason in first Excel.
Please Help.
This is the first Excel sheet - Reason_Name column contains Reason1, Reason2, etc.
alt text http://www.freeimagehosting.net/uploads/a10d6be7a5.png
This is the second Excel sheet
alt text http://www.freeimagehosting.net/uploads/99e0ff4cdb.png
Here's something that may get you started. (I think this is close to what you would like to do.)
Create a named range for the data on the second sheet. Named "new_range" in my example.
Then create the following procedure in a new module:
Sub FilterSheetTwo()
Worksheets("Sheet2").Range("new_range").AutoFilter Field:=6, Criteria1:="Reason1"
End Sub
When you run this procedure, it should filter the results on Sheet2.
You can then hook this procedure up to an Worksheet_Change event on Sheet1.
If you can sort your Reason column on the second sheet and place it as the left-most column you don't need a macro--you can do this using VLOOKUP. Steps:
Sort Data by your Reason column on the second sheet.
In each column of the first sheet enter the following formula:
=VLOOKUP(E2, DataRangeOfSheet2, ColumnYouWantFromDataRange)
See VLOOKUP for more info.