Excel formula into all cell array - vba

Im trying to fill in a formula in a lot of cells using a VBA. The workbook I'm working with looks like this:
I'm trying to fill in a formula starting in B3. I first tried to define a range and insert formula, but my problem is that the range is never the same. Some data sets I have more columns and others i have more rows.
Is there a way to make a VBA that defines the range as all columns with content in Row1 and all rows with content in A?
The formula that I'm trying to inset is like this: =INDEX(Sheet1!$N:$N;MATCH(Sheet3!$A:$A&Sheet3!B$1;Sheet1!$R:$R;0))
I hope someone can help me with my problem.

you could create a dynamic named range that can be used in VBA
Use the below to define the range
=OFFSET(Sheet1!$B$3,0,0,COUNTA(Sheet1!$A:$A)-1,COUNTA(Sheet1!$1:$1)-1)
Changing Sheet1 to that of your sheetname
Assuming that there areno blank columns or rowsin your data set etc.

Related

Need VBA script to extend Excel table every week

The problem is as follows: I have several tables in Excel with given number of raws and dynamic number of columns (each week a new column should be added, currently I'm doing it manually). I want to automate it and create a script that will extend every raw range to the next column (namely the range from A2 to C2 should become from A2 to D2), and so on (such that running script N times will result in extending a table to N columns further). By "extending" I mean extending formulas, since each cell in my tables contains any formula. Is there any way to do it via VBA?
I can't just record the corresponding macro because I have now idea how to specify that I don't want to link it with any specific range, but instead always extend just to one column right.
Any help and examples will be very appreciative.
You dont need VBA to do this. Use dynamic defined names and reference them in your formulas. For example, if you add a named range and add this in the refersTo dialog
=OFFSET($A$1,0,0,COUNTA($A:$A),COUNTA($1:$1)
your range will automatically expand from cell A1 (as long as there are no blank cells in column A or Row 1). You can then use that named range in your formulae.
More here http://www.excel-easy.com/examples/dynamic-named-range.html

Formulas to Switch Row and Column References in Excel

I have raw data that is arranged like this:
The top row is the trial number. Then the first entry in each row is an ID.
I'm trying to set up a template for this data. When this data is pasted in, I want it to be read by another sheet. This sheet will automatically transpose the data, so that it looks like this:
On this sheet, then, I've been trying to write a formula that will increment horizontally when dragged down vertically. When I copy the formula horizontally, I would need it to increase the row reference, not the column reference, so that it'll reproduce the end result in the screenshot above.
I've tried variations on a formula like
INDEX('Asset Returns'!$B$2:$Z$2,COLUMN()-1,ROW()-1)
but I haven't been able to get it working as described. Thanks in advance for any suggestions on what I'm doing wrong.
Not sure if I've understood, but if what you're doing is transposition, but wanting to do it via a common forumla in all the destination cells, you can do it using this:
=INDIRECT(ADDRESS(COLUMN(A1),ROW(A1),1,1,"Asset Returns"))
This should be pasted into the A1 cell of your "transposed" sheet, or adjust the cell reference accordingly if that isn't where the data is.
Another option is:
=OFFSET('Asset Returns'!$A$1,COLUMN(A1)-1,ROW(A1)-1)

Inherit Cell Colour Using VBA

I have a vlookup formula that is pulling results from table A and the cell that contains the results are coloured differently. I would like the colour of the cell to be inherited from table A to table B.
What would be the VBA formula to achieve this please?
Many thanks!

Spliting cells in excel based on some parameter

I wanted to know who can the following content be split in to two cells:
if i have C:\Pgm\Win\a1.c
in one cell
how can i split it in to two cells
C:\Pgm\Win a1.c
In my excel I have around 500 such rows.Is their any key availabe to do. I am using excel 2007.
You can use formulas to do the split
Assuming first string is in cell A1, place these formulas
Cell B1
=LEFT(A1,FIND("*",SUBSTITUTE(A1,"\","*",LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))))-1)
Cell C1
=RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,"\","*",LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))))
Copy down for all data rows
Once these formulas are calculated, you can copy/paste values and delete the original data if required
by using data to columns ....we can get...in to multiple columns...but it will not be an 100% solution

How to loop over a multi-row/column range per column using Excel 2007 VBA?

I'm looping to loop over a range with multiple rows and columns using Excel 2007 VBA.
I'm specifically trying to loop over a user selected range, and perform a calculation on each column in the range, and output the calculation two rows below each column.
You can retrieve the currently selected range by using
Application.Selection.Address
This will give you a range value (the Selection property returns a Range object) that will look something like "$B$4:$J$20".
Given you now have a range to work with, you can iterate across each column using something like:
For Each col In userSelectedRange.Columns
...
Next
The Columns property again returns a Range object that you can either iterate over further or perform other calculations on (your exact needs aren't too clear from your question).
To post the calculated result two rows above each column (e.g. a subtotal or similar), try using the Offset function:
Cells.Offset(-2, 0)
If you're able to provide more specifics around the sort of calculation you want, I may be able to add more detail into how you achieve it.