How to apply a formula to only visible cells macro - excel

I have a spreadsheet where I filter from row 1 column W and then apply a formula to the next visible cell. The next visible cell varies each week. It could be 1160 one week then 1165 the next, etc.
How can I write macro code that will pick up on the next visible cell no matter what row it is. It could be something simple that says "start on E1 and drop down to the next visible cell in column E" because then I don't mind using active cell formula entry.
Does anyone have any ideas? Thank you.
Here's what I have:
With Sheets("Data").Range.SpecialCells(xlCellTypeVisible)("W1")
.Value = "My Formula"
End With

If I understand the problem correctly:
With Sheets("Data").Range("W:W").SpecialCells(xlCellTypeVisible).Cells(2)
.Formula = "My Formula"
End With

Related

Active macro when a formula changes a cell to True

I am looking for some code to activate another macro when the cell changes to "True" (Cell Q1). The cell has a formula behind it: =IF(COUNTIF($T$2:$T$1618,"Implemented-N"),"No","Yes")
This formula reads a range of cells, which have a formula behind them (Column T). Column T matches and puts together the data in 2 other cells along the same row: =D2&"-"&N2
When a cell in Column T turns to "Implemented-N" it returns the value of "No" to Cell Q1.
When cell Q1 changes to "No" I would like my macro that calls up an email to be activated.
I have the code for the email but can't get it to activate when cell Q1 changes to "No".
Can anyone please help me?
As Scott mentioned in the comments something like the following would do the trick:
Private Sub Worksheet_Calculate()
If Range("Q1").Value = "No" Then Call YourMacro
'if the value of Q1 changes to No then call your macro/code
End Sub

Excel VBA Index Match Only Blank Row [duplicate]

So I have a column with blanks randomly throughout...I need a macro that would select only the blanks, and then in those blank cells paste in the value of the cell above it. The select part is obviously easy, but I keep getting errors about 'too many continuations' when trying to fill the formula down into the blanks. I included a picture, the first column is a 'before' and the second is how I want the column to look after the application of the macro.
If the macro needs to create a second column or something that's fine too, as long as the end result looks like it does in the picture. Thanks!
Picture to illustrate.
try,
sub fillblankfromabove()
dim blnks as range
with worksheets("Sheet1").Columns("E").Cells
set blnks = .specialcells(xlcelltypeblanks)
if not blnks is nothing then
blnks.formular1c1 = "=r[-1]c"
end if
.value = .value
end with
end sub
Another way to do this is to select all cells that you want included in this process, press CTRL + G, select Special, then select 'Blank Cells'. This will select all blank cells within your selected range. Then enter =[cell above] and press CTRL + ENTER and it will enter that formula into all selected cells.

Display value (result of formula) rather than formula in fomula bar

Here is the problem:
My table is very large and the column width is not enough to show all the text in it.
Since the text/value is generated by a formula in the cell, if I click on the cell, the Formula Bar will display the formula and not the value. Of course.
However, I think it is very useful to quickly know the content of the cell generated by the formula. If I expand the column width every time is not quick and clean.
Do you know if there is a way to solve the problem?
No there is not a way to show it in the formula bar if there is a formula in the cell.
The best thing I can suggest is to leave row 1 empty and merge A1:N1 together or similar, ,freeze row 1 if necessary
then put this formula into A1
=INDIRECT(CELL("address"))
When you select a cell on the sheet , press F9 on the keyboard and you can read the full value of the active cell in row 1
With a little VBA in the sheet you can also have it automatically update the cell
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Calculate
End Sub
Here's another solution. Simply assign a key to the following macro:
Sub DislayCellValue()
Dim outp As String
outp = "The value in the active cell is:" & Chr(13) & Chr(13) & ActiveCell.Value
MsgBox Prompt:=outp
End Sub
To display the value in a cell, click on the cell and hit Ctrl-(key).This might be helpful.

EXCEL - dropdown and fill cells

Good night.
I'm having some troubles to get what i need done.
I have some cells in a sheet that needs to be filled every day, manually.
I have also a dropdown with all the months, and another one with the days.
Is it possible to save data in specific cells for the selected dropdown values?
Something like for each day mantain different data in the same cells.
Thanks.
I'm not exactly sure what you are requesting. What I think you are trying to do is:
Enter something into a cell
Select the Month and Day from the dropdown lists
Record the value of the dropdowns into cells near the value you entered.
Is this correct? If so, you would need to need to write a VBA macro that would take the values of the dropdown and write them into the cells where you needed them to be (presume next to your entered text). I think this would do that for you.
Sub writeDropdowns()
'This will take the values from cells B1 and C1
'and record this in the two cells next to the selected cell
Selection.Offset(0, 1).Value = ActiveSheet.Range("B1")
Selection.Offset(0, 2).Value = ActiveSheet.Range("C1")
End Sub
It assumes that the dropdown values are in cell B1 and C1 of the same sheet.You could then link this macro to a Form button. This is very simple and doesn't check for any errors, like if there is no cell selected. It should be a good starting point though.

i want to merge cells with vba

im new to this and i want to ask one question if anyone can help.
im working with excel 2003 and what i want is that i have one column which at cell A1 i have name and in cell A2 i have surname, in cell A3 i have name and in cell A4 i have surname and so on.
what i want to do is to merge cell A1 with A2 and then A3 with A4 and so on.
its about 3000 rows.
is there any vba code to do it automatically?
You don't really need a VBA program for this, just use Excel formulas as so:
In the column next to your names fill a sequential list of numbers starting with 1. So this should have 1, 2, 3, 4 and so forth. You can go to the bottom of your A column, but half-way will be fine. TO do this quickly, type a 1 in the first row (B1), then in the second (B2) add a formula: =B1+1. Then copy this formula all the way down B column to the extent of the A column. The trick here is to go to B2, select Edit/Copy, then move to A column and Ctrl-Down, move to the B column and then use Shift+Ctrl-Up, then paste.
In C column you will put a formula to merge two cells together from A column, as so:
=INDEX($A$1:$A$<ENDROW>,(B1-1)*2+1,1)&" "&INDEX($A$1:$A$<ENDROW>,(B1-1)*2+2,1)
Where <ENDROW> is the last row in A.
Copy this formula down at least half the rows of the A column. If you go beyond this, you will get #REF! error; just clear those cells.
Now you want to copy the formulas in C to another column, say D. Select them, use Edit/Copy, then move to D1 and right-click and choose "Paste special". In the dialog click on "Values" and then "OK". Now you have a column with the values of every two rows concatenated together.
to do this in vba:
Sub nameMerger()
Range("A1").Select
While ActiveCell.Value <> vbNullString
ActiveCell.Value = ActiveCell.Value & " " & ActiveCell.Offset(0, 1).Value
ActiveCell.Offset(0, 1).EntireColumn.Delete
ActiveCell.Offset(0, 1).Select
Wend
End Sub
Tested and works

Resources