Issue using IF=() function in Excel 2010 - excel

I am new to this forum and I am seeking help with creating a function in Excel for data logging purposes. Basically I am trying to use Excel to write a macro simply by pressing "x" in certain cells. For instance, from cells A3-A6 I will have client's names listed there. In addition, I will have dates (of service) listed on the 2nd cell row and on.
9/20 9/21 9/22 9/24
John Doe x
Sara Mitchell x x
Christopher Acha x
Now, I have the macro, I have everything I need in order to set this up. The only problem I am having is to make Excel write the macro for me. I am trying to use the IF=() function, but it limits me to 255 characters, and it tells me to use the concatenate function. All I am trying to do is basically tell Excel that if a certain cell IS true, I would mark it by hitting x; meaning that if a person came on the 24th for service, I would hit x and from there excel would automatically write what I tell it to (in a different sheet or cell). I am stuck here, any help would be greatly appreciated.

You said you have a macro that works, so I'm assuming you want to know how to trigger it automatically when you enter data into a cell.
In your worksheet code use a change event and call your macro from here and pass the range you sent.
Private Sub Worksheet_Change(ByVal Target As Range)
myMacro(Target)
End Sub
You'll probably want to add in additional code to test that the cell changed is within a certain range before calling your macro.

Related

Make variable hyperlink from cell data

Hi I am kind of new to VBA and i can't seem to find what i am looking for.
What i want to make is a macro that links to another page in my workbook that refers to data in a certain cell.
from certain datapoints i have a cell set up that as everything is filled in it gives the name of the page i want to link to (lets say "overview_Oct_2020" by filling in the month and year in other cells), and when running the macro go to that.
I seem to totally blank on how to do it. I made a =HYPERLINK() version pretty easily, but i want to change that to a button, hence the reason for a macro.
so technically i want to make a button with a macro that goes to [TEXT IN CEL A1]!A1
Put this macro in a standard module and assign it to a button on the worksheet
Sub link()
Dim textInCelA1 as String
textInCelA1 = Range("A1").value
Sheets(textInCelA1).Activate
Range("A1").Select
End Sub

How to determine what VBA code is changing the value of an Excel cell

I have a workbook written by someone else and a particular cell is being changed by some code. I cannot figure out the code that is changing the cell value.
I cannot even figure out a strategy to narrow down the code possibilities apart from setting a breakpoint in hundreds of procedures. So I would be happy with strategy ideas.
I am very experienced using VBA in Microsoft Access and a little bit experienced using VBA in Excel.
EDIT
Gotta larf. I cannot even F8 throught the code by starting at the start. What I mean is..
The cell in question changes after I change a value (a year actually) in the worksheet. So I set up a subroutine and breakpoint as below.
Private Sub Worksheet_Change(ByVal Target As Range)
End Sub '<== set breakpoint here
Then I press F8 and no other code is entered by the debugger and yet the cell changes.
The problem may be because there is an awful lot of dynamic formula creation going on in the code. Not sure. Don't know enough about Excel quirks.
EDIT 2
There is a missing formula in the cell in question. Sorry to have wasted everyone's time.
So how can a missing formula change a cell's value. It can't!
The question should have been "How to determine why a cell is NOT changing."
So why didn't I ask that?
I did not notice that other cells in the same column as this cell contain a formula. Because the other cells were changing values correctly and this cell was not, I presumed it was some VBA code not working so I tried to track down the rogue code. I guess not being an experienced Excel person I did not rule out the bleeding obvious and went straight to VBA. Phew!
Add a change event handler on the sheet containing the cell you want to track.
In that Event Handler, add code to break when a change in the tracked cell takes place
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Cells(1, 1)) Is Nothing Then
Stop
End If
End Sub
Chnage Me.Cells(1, 1) to cell of your choosing.
When the code breaks, open the Call Stack, to see where the change came from
Here's a proof of concept. I ran ZX. Call stack shows the Change event at the top. The next function is what changed to cell.

Freezing certain cells - VBA

I have a question about freezing certain cells. But first let me explain the situation.
I have made a search box in my excel sheet and when you search for a letter or word; the results show up in cells below the search box. Now I want to freeze those cells, so that wherever I go in my sheet. I can always use the search box and see the results.
The cells for the searchbox and results are B2:B25. Those are the ones I want to freeze. Also the only sheet I want to use this on is the sheet "Reading". On the rest of my sheets I do not use a search function.
So my question(s) is : Do I need to put the code inside a module or on that sheet, and how do I do this?
Now I have tried the following
Range(Cells(2,2), Cells(25, 2)).Select
ActiveWindow(or maybe Reading?).FreezePanes = True
Inside a module. But it did not work and I do not know what else to do.
Any help is much appreciated! Since I am very new to VBA.
Almost there. Problem is that the 'range' and 'cells' needs to be directed to the 'Reading' sheet, like so:
Sheets("Reading").Range(Sheets("Reading").Cells(2,2), Sheets("Reading").Cells(25, 2)).Select
ActiveWindow.FreezePanes = True
but if it always is B2->B25, why not use:
Sheets("Reading").Range("B2:B25").Select
ActiveWindow.FreezePanes = True
This should work. Select is not very desirable, because it is very slow, but in this case, you need to (as far as I know).
EDIT
BTW, you can do this from within a code module or from within a sheet, but if you choose to do it from within a sheet, you cannot select another sheet. So just use the range.
EDIT 2
whoopsy, typo corrected. 'Sheet' should have been 'Sheets'

Auto Resize Row Height after pasting in Excel

I use MS Excel 2007 to make Bills and Quotation. Often I need to reuse previous quotation.
After I copy a quotation and paste it to new location the row height needs to be readjusted for each row.
is there any solution to this?
I'm not totally sure if this is what you are after. But have you tried something like this?
Private Sub Worksheet_Change(ByVal Target As Range)
' Here you enter a matrix with the cells you want to trigger a Autofit
' If you just want one column to do it, take Range("A1:A200")
Range("A1:C11").EntireRow.AutoFit
End Sub
This code gets the row-size auto-fitted everytime you change the value in the choosen cells.
It's hard to come up with a good solution when you do not give to much information.
Check here :
Excel Worksheet_Change Event not working if my code didn't help you.
Best Regards

Automatically execute an excel macro on a cell changed by a real-time add-in

I have an Excel add-in (Bloomberg) which streams real-time prices into a spreadsheet. I need to add a column which contains the last time a price was updated. I've tried to do this with the worksheet change event, but this doesn't seem to get fired by the changes (I assume something to do with it being a real-time update).
The requirement is the same as the question below, but the solutions do not apply since the events do not fire in this case.
automatically execute an Excel macro on a cell change
With help from another forum, I've found an easy way to do this.
First define a function as below in a VBA module accessible to the sheet:
Public Function GetTime(target As Double) As Double
GetTime = Now()
End Function
Then in the 'last updated' column, add a call to this function with the formula pointing to the cell you wish to monitor. Whenever the target cell is updated, even from a real-time update, the function will fire and cause the time to be updated.

Resources